| using System; |
| using System; |
| using System.Collections; |
| using System.Collections; |
| using System.Collections.Generic; |
| using System.Collections.Generic; |
| using System.IO; |
| using System.IO; |
| using System.Linq; |
| using System.Linq; |
| using System.Net; |
| using System.Net; |
| using System.Net.Sockets; |
| using System.Net.Sockets; |
| using System.Runtime.CompilerServices; |
| using System.Runtime.CompilerServices; |
| using System.Security.Cryptography; |
| using System.Security.Cryptography; |
| using System.Text; |
| using System.Text; |
| using System.Text.RegularExpressions; |
| using System.Text.RegularExpressions; |
| using System.Threading; |
| using System.Threading; |
| using GUIFramework; |
| using GUIFramework; |
| using Steamworks; |
| using Steamworks; |
| using UnityEngine; |
| using UnityEngine; |
| using UnityEngine.Events; |
| using UnityEngine.Events; |
| using UnityEngine.Rendering; |
| using UnityEngine.Rendering; |
| using UserManagement; |
| using UserManagement; |
| |
| |
| public class ZNet : MonoBehaviour |
| public class ZNet : MonoBehaviour |
| { |
| { |
| public static ZNet instance |
| public static ZNet instance |
| { |
| { |
| get |
| get |
| { |
| { |
| return ZNet.m_instance; |
| return ZNet.m_instance; |
| } |
| } |
| } |
| } |
| |
| |
| private void Awake() |
| private void Awake() |
| { |
| { |
| ZNet.m_instance = this; |
| ZNet.m_instance = this; |
| ZNet.m_loadError = false; |
| ZNet.m_loadError = false; |
| this.m_routedRpc = new ZRoutedRpc(ZNet.m_isServer); |
| this.m_routedRpc = new ZRoutedRpc(ZNet.m_isServer); |
| this.m_zdoMan = new ZDOMan(this.m_zdoSectorsWidth); |
| this.m_zdoMan = new ZDOMan(this.m_zdoSectorsWidth); |
| this.m_passwordDialog.gameObject.SetActive(false); |
| this.m_passwordDialog.gameObject.SetActive(false); |
| this.m_connectingDialog.gameObject.SetActive(false); |
| this.m_connectingDialog.gameObject.SetActive(false); |
| WorldGenerator.Deitialize(); |
| WorldGenerator.Deitialize(); |
| if (SteamManager.Initialize()) |
| if (SteamManager.Initialize()) |
| { |
| { |
| string personaName = SteamFriends.GetPersonaName(); |
| string personaName = SteamFriends.GetPersonaName(); |
| ZLog.Log("Steam initialized, persona:" + personaName); |
| ZLog.Log("Steam initialized, persona:" + personaName); |
| ZSteamMatchmaking.Initialize(); |
| ZSteamMatchmaking.Initialize(); |
| ZPlayFabMatchmaking.Initialize(ZNet.m_isServer); |
| ZPlayFabMatchmaking.Initialize(ZNet.m_isServer); |
| ZNet.m_backupCount = PlatformPrefs.GetInt("AutoBackups", ZNet.m_backupCount); |
| ZNet.m_backupCount = PlatformPrefs.GetInt("AutoBackups", ZNet.m_backupCount); |
| ZNet.m_backupShort = PlatformPrefs.GetInt("AutoBackups_short", ZNet.m_backupShort); |
| ZNet.m_backupShort = PlatformPrefs.GetInt("AutoBackups_short", ZNet.m_backupShort); |
| ZNet.m_backupLong = PlatformPrefs.GetInt("AutoBackups_long", ZNet.m_backupLong); |
| ZNet.m_backupLong = PlatformPrefs.GetInt("AutoBackups_long", ZNet.m_backupLong); |
| if (ZNet.m_isServer) |
| if (ZNet.m_isServer) |
| { |
| { |
| this.m_adminList = new SyncedList(Utils.GetSaveDataPath(FileHelpers.FileSource.Local) + "/adminlist.txt", "List admin players ID ONE per line"); |
| this.m_adminList = new SyncedList(Utils.GetSaveDataPath(FileHelpers.FileSource.Local) + "/adminlist.txt", "List admin players ID ONE per line"); |
| this.m_bannedList = new SyncedList(Utils.GetSaveDataPath(FileHelpers.FileSource.Local) + "/bannedlist.txt", "List banned players ID ONE per line"); |
| this.m_bannedList = new SyncedList(Utils.GetSaveDataPath(FileHelpers.FileSource.Local) + "/bannedlist.txt", "List banned players ID ONE per line"); |
| this.m_permittedList = new SyncedList(Utils.GetSaveDataPath(FileHelpers.FileSource.Local) + "/permittedlist.txt", "List permitted players ID ONE per line"); |
| this.m_permittedList = new SyncedList(Utils.GetSaveDataPath(FileHelpers.FileSource.Local) + "/permittedlist.txt", "List permitted players ID ONE per line"); |
| this.m_adminListForRpc = this.m_adminList.GetList(); |
| this.m_adminListForRpc = this.m_adminList.GetList(); |
| if (ZNet.m_world == null) |
| if (ZNet.m_world == null) |
| { |
| { |
| ZNet.m_publicServer = false; |
| ZNet.m_publicServer = false; |
| ZNet.m_world = World.GetDevWorld(); |
| ZNet.m_world = World.GetDevWorld(); |
| } |
| } |
| if (ZNet.m_openServer) |
| if (ZNet.m_openServer) |
| { |
| { |
| bool flag = ZNet.m_serverPassword != ""; |
| bool flag = ZNet.m_serverPassword != ""; |
| GameVersion currentVersion = global::Version.CurrentVersion; |
| GameVersion currentVersion = global::Version.CurrentVersion; |
| . | uint num = 23U; |
| uint num = 27U; |
| List<string> startingGlobalKeys = ZNet.m_world.m_startingGlobalKeys; |
| List<string> startingGlobalKeys = ZNet.m_world.m_startingGlobalKeys; |
| ZSteamMatchmaking.instance.RegisterServer(ZNet.m_ServerName, flag, currentVersion, startingGlobalKeys, num, ZNet.m_publicServer, ZNet.m_world.m_seedName, new ZSteamMatchmaking.ServerRegistered(this.OnSteamServerRegistered)); |
| ZSteamMatchmaking.instance.RegisterServer(ZNet.m_ServerName, flag, currentVersion, startingGlobalKeys, num, ZNet.m_publicServer, ZNet.m_world.m_seedName, new ZSteamMatchmaking.ServerRegistered(this.OnSteamServerRegistered)); |
| if (ZNet.m_onlineBackend == OnlineBackendType.Steamworks) |
| if (ZNet.m_onlineBackend == OnlineBackendType.Steamworks) |
| { |
| { |
| ZSteamSocket zsteamSocket = new ZSteamSocket(); |
| ZSteamSocket zsteamSocket = new ZSteamSocket(); |
| zsteamSocket.StartHost(); |
| zsteamSocket.StartHost(); |
| this.m_hostSocket = zsteamSocket; |
| this.m_hostSocket = zsteamSocket; |
| } |
| } |
| if (ZNet.m_onlineBackend == OnlineBackendType.PlayFab) |
| if (ZNet.m_onlineBackend == OnlineBackendType.PlayFab) |
| { |
| { |
| ZPlayFabMatchmaking.instance.RegisterServer(ZNet.m_ServerName, flag, ZNet.m_publicServer, currentVersion, startingGlobalKeys, num, ZNet.m_world.m_seedName, true); |
| ZPlayFabMatchmaking.instance.RegisterServer(ZNet.m_ServerName, flag, ZNet.m_publicServer, currentVersion, startingGlobalKeys, num, ZNet.m_world.m_seedName, true); |
| ZPlayFabSocket zplayFabSocket = new ZPlayFabSocket(); |
| ZPlayFabSocket zplayFabSocket = new ZPlayFabSocket(); |
| zplayFabSocket.StartHost(); |
| zplayFabSocket.StartHost(); |
| this.m_hostSocket = zplayFabSocket; |
| this.m_hostSocket = zplayFabSocket; |
| } |
| } |
| } |
| } |
| WorldGenerator.Initialize(ZNet.m_world); |
| WorldGenerator.Initialize(ZNet.m_world); |
| ZNet.m_connectionStatus = ZNet.ConnectionStatus.Connected; |
| ZNet.m_connectionStatus = ZNet.ConnectionStatus.Connected; |
| ZNet.m_externalError = ZNet.ConnectionStatus.None; |
| ZNet.m_externalError = ZNet.ConnectionStatus.None; |
| } |
| } |
| this.m_routedRpc.SetUID(ZDOMan.GetSessionID()); |
| this.m_routedRpc.SetUID(ZDOMan.GetSessionID()); |
| if (this.IsServer()) |
| if (this.IsServer()) |
| { |
| { |
| this.SendPlayerList(); |
| this.SendPlayerList(); |
| } |
| } |
| return; |
| return; |
| } |
| } |
| } |
| } |
| |
| |
| private void Start() |
| private void Start() |
| { |
| { |
| ZRpc.SetLongTimeout(false); |
| ZRpc.SetLongTimeout(false); |
| ZLog.Log("ZNET START"); |
| ZLog.Log("ZNET START"); |
| BlockList.Load(null); |
| BlockList.Load(null); |
| if (ZNet.m_isServer) |
| if (ZNet.m_isServer) |
| { |
| { |
| this.ServerLoadWorld(); |
| this.ServerLoadWorld(); |
| return; |
| return; |
| } |
| } |
| this.ClientConnect(); |
| this.ClientConnect(); |
| } |
| } |
| |
| |
| private void ServerLoadWorld() |
| private void ServerLoadWorld() |
| { |
| { |
| this.LoadWorld(); |
| this.LoadWorld(); |
| ZoneSystem.instance.GenerateLocationsIfNeeded(); |
| ZoneSystem.instance.GenerateLocationsIfNeeded(); |
| if (ZNet.m_loadError) |
| if (ZNet.m_loadError) |
| { |
| { |
| ZLog.LogError("World db couldn't load correctly, saving has been disabled to prevent .old file from being overwritten."); |
| ZLog.LogError("World db couldn't load correctly, saving has been disabled to prevent .old file from being overwritten."); |
| } |
| } |
| } |
| } |
| |
| |
| private void ClientConnect() |
| private void ClientConnect() |
| { |
| { |
| if (ZNet.m_onlineBackend == OnlineBackendType.PlayFab) |
| if (ZNet.m_onlineBackend == OnlineBackendType.PlayFab) |
| { |
| { |
| ZLog.Log("Connecting to server with PlayFab-backend " + ZNet.m_serverPlayFabPlayerId); |
| ZLog.Log("Connecting to server with PlayFab-backend " + ZNet.m_serverPlayFabPlayerId); |
| this.Connect(ZNet.m_serverPlayFabPlayerId); |
| this.Connect(ZNet.m_serverPlayFabPlayerId); |
| } |
| } |
| if (ZNet.m_onlineBackend == OnlineBackendType.Steamworks) |
| if (ZNet.m_onlineBackend == OnlineBackendType.Steamworks) |
| { |
| { |
| if (ZNet.m_serverSteamID == 0UL) |
| if (ZNet.m_serverSteamID == 0UL) |
| { |
| { |
| ZLog.Log("Connecting to server with Steam-backend " + ZNet.m_serverHost + ":" + ZNet.m_serverHostPort.ToString()); |
| ZLog.Log("Connecting to server with Steam-backend " + ZNet.m_serverHost + ":" + ZNet.m_serverHostPort.ToString()); |
| SteamNetworkingIPAddr steamNetworkingIPAddr = default(SteamNetworkingIPAddr); |
| SteamNetworkingIPAddr steamNetworkingIPAddr = default(SteamNetworkingIPAddr); |
| steamNetworkingIPAddr.ParseString(ZNet.m_serverHost + ":" + ZNet.m_serverHostPort.ToString()); |
| steamNetworkingIPAddr.ParseString(ZNet.m_serverHost + ":" + ZNet.m_serverHostPort.ToString()); |
| this.Connect(steamNetworkingIPAddr); |
| this.Connect(steamNetworkingIPAddr); |
| return; |
| return; |
| } |
| } |
| ZLog.Log("Connecting to server with Steam-backend " + ZNet.m_serverSteamID.ToString()); |
| ZLog.Log("Connecting to server with Steam-backend " + ZNet.m_serverSteamID.ToString()); |
| this.Connect(new CSteamID(ZNet.m_serverSteamID)); |
| this.Connect(new CSteamID(ZNet.m_serverSteamID)); |
| } |
| } |
| if (ZNet.m_onlineBackend == OnlineBackendType.CustomSocket) |
| if (ZNet.m_onlineBackend == OnlineBackendType.CustomSocket) |
| { |
| { |
| ZLog.Log("Connecting to server with socket-backend " + ZNet.m_serverHost + " " + ZNet.m_serverHostPort.ToString()); |
| ZLog.Log("Connecting to server with socket-backend " + ZNet.m_serverHost + " " + ZNet.m_serverHostPort.ToString()); |
| this.Connect(ZNet.m_serverHost, ZNet.m_serverHostPort); |
| this.Connect(ZNet.m_serverHost, ZNet.m_serverHostPort); |
| } |
| } |
| } |
| } |
| |
| |
| private string GetServerIP() |
| private string GetServerIP() |
| { |
| { |
| return ZNet.GetPublicIP(); |
| return ZNet.GetPublicIP(); |
| } |
| } |
| |
| |
| private string LocalIPAddress() |
| private string LocalIPAddress() |
| { |
| { |
| string text = IPAddress.Loopback.ToString(); |
| string text = IPAddress.Loopback.ToString(); |
| try |
| try |
| { |
| { |
| foreach (IPAddress ipaddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList) |
| foreach (IPAddress ipaddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList) |
| { |
| { |
| if (ipaddress.AddressFamily == AddressFamily.InterNetwork) |
| if (ipaddress.AddressFamily == AddressFamily.InterNetwork) |
| { |
| { |
| text = ipaddress.ToString(); |
| text = ipaddress.ToString(); |
| break; |
| break; |
| } |
| } |
| } |
| } |
| } |
| } |
| catch (Exception ex) |
| catch (Exception ex) |
| { |
| { |
| ZLog.Log(string.Format("Failed to get local address, using {0}: {1}", text, ex.Message)); |
| ZLog.Log(string.Format("Failed to get local address, using {0}: {1}", text, ex.Message)); |
| } |
| } |
| return text; |
| return text; |
| } |
| } |
| |
| |
| public static string GetPublicIP() |
| public static string GetPublicIP() |
| { |
| { |
| string text2; |
| string text2; |
| try |
| try |
| { |
| { |
| string[] array = new string[] { "http://checkip.dyndns.org/", "http://icanhazip.com", "https://checkip.amazonaws.com/", "https://ipinfo.io/ip/", "https://wtfismyip.com/text" }; |
| string[] array = new string[] { "http://checkip.dyndns.org/", "http://icanhazip.com", "https://checkip.amazonaws.com/", "https://ipinfo.io/ip/", "https://wtfismyip.com/text" }; |
| System.Random random = new System.Random(); |
| System.Random random = new System.Random(); |
| string text = ZNet.<GetPublicIP>g__DownloadString|10_0(array[random.Next(array.Length)], 5000); |
| string text = ZNet.<GetPublicIP>g__DownloadString|10_0(array[random.Next(array.Length)], 5000); |
| text = new Regex("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}").Matches(text)[0].ToString(); |
| text = new Regex("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}").Matches(text)[0].ToString(); |
| text2 = text; |
| text2 = text; |
| } |
| } |
| catch (Exception ex) |
| catch (Exception ex) |
| { |
| { |
| ZLog.LogError(ex.Message); |
| ZLog.LogError(ex.Message); |
| text2 = ""; |
| text2 = ""; |
| } |
| } |
| return text2; |
| return text2; |
| } |
| } |
| |
| |
| private void OnSteamServerRegistered(bool success) |
| private void OnSteamServerRegistered(bool success) |
| { |
| { |
| if (!success) |
| if (!success) |
| { |
| { |
| this.m_registerAttempts++; |
| this.m_registerAttempts++; |
| float num = 1f * Mathf.Pow(2f, (float)(this.m_registerAttempts - 1)); |
| float num = 1f * Mathf.Pow(2f, (float)(this.m_registerAttempts - 1)); |
| num = Mathf.Min(num, 30f); |
| num = Mathf.Min(num, 30f); |
| num *= UnityEngine.Random.Range(0.875f, 1.125f); |
| num *= UnityEngine.Random.Range(0.875f, 1.125f); |
| this.<OnSteamServerRegistered>g__RetryRegisterAfterDelay|11_0(num); |
| this.<OnSteamServerRegistered>g__RetryRegisterAfterDelay|11_0(num); |
| } |
| } |
| } |
| } |
| |
| |
| public void Shutdown(bool save = true) |
| public void Shutdown(bool save = true) |
| { |
| { |
| ZLog.Log("ZNet Shutdown"); |
| ZLog.Log("ZNet Shutdown"); |
| if (save) |
| if (save) |
| { |
| { |
| this.Save(true, false); |
| this.Save(true, false); |
| } |
| } |
| this.StopAll(); |
| this.StopAll(); |
| base.enabled = false; |
| base.enabled = false; |
| } |
| } |
| |
| |
| public void ShutdownWithoutSave() |
| public void ShutdownWithoutSave() |
| { |
| { |
| ZLog.Log("ZNet Shutdown without save"); |
| ZLog.Log("ZNet Shutdown without save"); |
| this.StopAll(); |
| this.StopAll(); |
| base.enabled = false; |
| base.enabled = false; |
| } |
| } |
| |
| |
| private void StopAll() |
| private void StopAll() |
| { |
| { |
| if (this.m_haveStoped) |
| if (this.m_haveStoped) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| this.m_haveStoped = true; |
| this.m_haveStoped = true; |
| if (this.m_saveThread != null && this.m_saveThread.IsAlive) |
| if (this.m_saveThread != null && this.m_saveThread.IsAlive) |
| { |
| { |
| this.m_saveThread.Join(); |
| this.m_saveThread.Join(); |
| this.m_saveThread = null; |
| this.m_saveThread = null; |
| } |
| } |
| this.m_zdoMan.ShutDown(); |
| this.m_zdoMan.ShutDown(); |
| this.SendDisconnect(); |
| this.SendDisconnect(); |
| ZSteamMatchmaking.instance.ReleaseSessionTicket(); |
| ZSteamMatchmaking.instance.ReleaseSessionTicket(); |
| ZSteamMatchmaking.instance.UnregisterServer(); |
| ZSteamMatchmaking.instance.UnregisterServer(); |
| ZPlayFabMatchmaking instance = ZPlayFabMatchmaking.instance; |
| ZPlayFabMatchmaking instance = ZPlayFabMatchmaking.instance; |
| if (instance != null) |
| if (instance != null) |
| { |
| { |
| instance.UnregisterServer(); |
| instance.UnregisterServer(); |
| } |
| } |
| if (this.m_hostSocket != null) |
| if (this.m_hostSocket != null) |
| { |
| { |
| this.m_hostSocket.Dispose(); |
| this.m_hostSocket.Dispose(); |
| } |
| } |
| if (this.m_serverConnector != null) |
| if (this.m_serverConnector != null) |
| { |
| { |
| this.m_serverConnector.Dispose(); |
| this.m_serverConnector.Dispose(); |
| } |
| } |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| { |
| { |
| znetPeer.Dispose(); |
| znetPeer.Dispose(); |
| } |
| } |
| this.m_peers.Clear(); |
| this.m_peers.Clear(); |
| } |
| } |
| |
| |
| private void OnDestroy() |
| private void OnDestroy() |
| { |
| { |
| ZLog.Log("ZNet OnDestroy"); |
| ZLog.Log("ZNet OnDestroy"); |
| if (ZNet.m_instance == this) |
| if (ZNet.m_instance == this) |
| { |
| { |
| ZNet.m_instance = null; |
| ZNet.m_instance = null; |
| } |
| } |
| } |
| } |
| |
| |
| private ZNetPeer Connect(ISocket socket) |
| private ZNetPeer Connect(ISocket socket) |
| { |
| { |
| ZNetPeer znetPeer = new ZNetPeer(socket, true); |
| ZNetPeer znetPeer = new ZNetPeer(socket, true); |
| this.OnNewConnection(znetPeer); |
| this.OnNewConnection(znetPeer); |
| ZNet.m_connectionStatus = ZNet.ConnectionStatus.Connecting; |
| ZNet.m_connectionStatus = ZNet.ConnectionStatus.Connecting; |
| ZNet.m_externalError = ZNet.ConnectionStatus.None; |
| ZNet.m_externalError = ZNet.ConnectionStatus.None; |
| this.m_connectingDialog.gameObject.SetActive(true); |
| this.m_connectingDialog.gameObject.SetActive(true); |
| return znetPeer; |
| return znetPeer; |
| } |
| } |
| |
| |
| public void Connect(string remotePlayerId) |
| public void Connect(string remotePlayerId) |
| { |
| { |
| ZNet.<>c__DisplayClass17_0 CS$<>8__locals1 = new ZNet.<>c__DisplayClass17_0(); |
| ZNet.<>c__DisplayClass17_0 CS$<>8__locals1 = new ZNet.<>c__DisplayClass17_0(); |
| CS$<>8__locals1.<>4__this = this; |
| CS$<>8__locals1.<>4__this = this; |
| CS$<>8__locals1.socket = null; |
| CS$<>8__locals1.socket = null; |
| CS$<>8__locals1.peer = null; |
| CS$<>8__locals1.peer = null; |
| CS$<>8__locals1.socket = new ZPlayFabSocket(remotePlayerId, new Action<PlayFabMatchmakingServerData>(CS$<>8__locals1.<Connect>g__CheckServerData|0)); |
| CS$<>8__locals1.socket = new ZPlayFabSocket(remotePlayerId, new Action<PlayFabMatchmakingServerData>(CS$<>8__locals1.<Connect>g__CheckServerData|0)); |
| CS$<>8__locals1.peer = this.Connect(CS$<>8__locals1.socket); |
| CS$<>8__locals1.peer = this.Connect(CS$<>8__locals1.socket); |
| } |
| } |
| |
| |
| public void Connect(CSteamID hostID) |
| public void Connect(CSteamID hostID) |
| { |
| { |
| this.Connect(new ZSteamSocket(hostID)); |
| this.Connect(new ZSteamSocket(hostID)); |
| } |
| } |
| |
| |
| public void Connect(SteamNetworkingIPAddr host) |
| public void Connect(SteamNetworkingIPAddr host) |
| { |
| { |
| this.Connect(new ZSteamSocket(host)); |
| this.Connect(new ZSteamSocket(host)); |
| } |
| } |
| |
| |
| public void Connect(string host, int port) |
| public void Connect(string host, int port) |
| { |
| { |
| this.m_serverConnector = new ZConnector2(host, port); |
| this.m_serverConnector = new ZConnector2(host, port); |
| ZNet.m_connectionStatus = ZNet.ConnectionStatus.Connecting; |
| ZNet.m_connectionStatus = ZNet.ConnectionStatus.Connecting; |
| ZNet.m_externalError = ZNet.ConnectionStatus.None; |
| ZNet.m_externalError = ZNet.ConnectionStatus.None; |
| this.m_connectingDialog.gameObject.SetActive(true); |
| this.m_connectingDialog.gameObject.SetActive(true); |
| } |
| } |
| |
| |
| private void UpdateClientConnector(float dt) |
| private void UpdateClientConnector(float dt) |
| { |
| { |
| if (this.m_serverConnector != null && this.m_serverConnector.UpdateStatus(dt, true)) |
| if (this.m_serverConnector != null && this.m_serverConnector.UpdateStatus(dt, true)) |
| { |
| { |
| ZSocket2 zsocket = this.m_serverConnector.Complete(); |
| ZSocket2 zsocket = this.m_serverConnector.Complete(); |
| if (zsocket != null) |
| if (zsocket != null) |
| { |
| { |
| ZLog.Log("Connection established to " + this.m_serverConnector.GetEndPointString()); |
| ZLog.Log("Connection established to " + this.m_serverConnector.GetEndPointString()); |
| ZNetPeer znetPeer = new ZNetPeer(zsocket, true); |
| ZNetPeer znetPeer = new ZNetPeer(zsocket, true); |
| this.OnNewConnection(znetPeer); |
| this.OnNewConnection(znetPeer); |
| } |
| } |
| else |
| else |
| { |
| { |
| ZNet.m_connectionStatus = ZNet.ConnectionStatus.ErrorConnectFailed; |
| ZNet.m_connectionStatus = ZNet.ConnectionStatus.ErrorConnectFailed; |
| ZLog.Log("Failed to connect to server"); |
| ZLog.Log("Failed to connect to server"); |
| } |
| } |
| this.m_serverConnector.Dispose(); |
| this.m_serverConnector.Dispose(); |
| this.m_serverConnector = null; |
| this.m_serverConnector = null; |
| } |
| } |
| } |
| } |
| |
| |
| private void OnNewConnection(ZNetPeer peer) |
| private void OnNewConnection(ZNetPeer peer) |
| { |
| { |
| this.m_peers.Add(peer); |
| this.m_peers.Add(peer); |
| peer.m_rpc.Register<ZPackage>("PeerInfo", new Action<ZRpc, ZPackage>(this.RPC_PeerInfo)); |
| peer.m_rpc.Register<ZPackage>("PeerInfo", new Action<ZRpc, ZPackage>(this.RPC_PeerInfo)); |
| peer.m_rpc.Register("Disconnect", new ZRpc.RpcMethod.Method(this.RPC_Disconnect)); |
| peer.m_rpc.Register("Disconnect", new ZRpc.RpcMethod.Method(this.RPC_Disconnect)); |
| peer.m_rpc.Register("SavePlayerProfile", new ZRpc.RpcMethod.Method(this.RPC_SavePlayerProfile)); |
| peer.m_rpc.Register("SavePlayerProfile", new ZRpc.RpcMethod.Method(this.RPC_SavePlayerProfile)); |
| if (ZNet.m_isServer) |
| if (ZNet.m_isServer) |
| { |
| { |
| peer.m_rpc.Register("ServerHandshake", new ZRpc.RpcMethod.Method(this.RPC_ServerHandshake)); |
| peer.m_rpc.Register("ServerHandshake", new ZRpc.RpcMethod.Method(this.RPC_ServerHandshake)); |
| return; |
| return; |
| } |
| } |
| peer.m_rpc.Register("Kicked", new ZRpc.RpcMethod.Method(this.RPC_Kicked)); |
| peer.m_rpc.Register("Kicked", new ZRpc.RpcMethod.Method(this.RPC_Kicked)); |
| peer.m_rpc.Register<int>("Error", new Action<ZRpc, int>(this.RPC_Error)); |
| peer.m_rpc.Register<int>("Error", new Action<ZRpc, int>(this.RPC_Error)); |
| peer.m_rpc.Register<bool, string>("ClientHandshake", new Action<ZRpc, bool, string>(this.RPC_ClientHandshake)); |
| peer.m_rpc.Register<bool, string>("ClientHandshake", new Action<ZRpc, bool, string>(this.RPC_ClientHandshake)); |
| peer.m_rpc.Invoke("ServerHandshake", Array.Empty<object>()); |
| peer.m_rpc.Invoke("ServerHandshake", Array.Empty<object>()); |
| } |
| } |
| |
| |
| public void SaveOtherPlayerProfiles() |
| public void SaveOtherPlayerProfiles() |
| { |
| { |
| ZLog.Log("Sending message to save player profiles"); |
| ZLog.Log("Sending message to save player profiles"); |
| if (!this.IsServer()) |
| if (!this.IsServer()) |
| { |
| { |
| ZLog.Log("Only server can save the player profiles"); |
| ZLog.Log("Only server can save the player profiles"); |
| return; |
| return; |
| } |
| } |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| { |
| { |
| if (znetPeer.m_rpc != null) |
| if (znetPeer.m_rpc != null) |
| { |
| { |
| ZLog.Log("Sent to " + znetPeer.m_socket.GetEndPointString()); |
| ZLog.Log("Sent to " + znetPeer.m_socket.GetEndPointString()); |
| znetPeer.m_rpc.Invoke("SavePlayerProfile", Array.Empty<object>()); |
| znetPeer.m_rpc.Invoke("SavePlayerProfile", Array.Empty<object>()); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| private void RPC_SavePlayerProfile(ZRpc rpc) |
| private void RPC_SavePlayerProfile(ZRpc rpc) |
| { |
| { |
| Game.instance.SavePlayerProfile(true); |
| Game.instance.SavePlayerProfile(true); |
| } |
| } |
| |
| |
| private void RPC_ServerHandshake(ZRpc rpc) |
| private void RPC_ServerHandshake(ZRpc rpc) |
| { |
| { |
| ZNetPeer peer = this.GetPeer(rpc); |
| ZNetPeer peer = this.GetPeer(rpc); |
| if (peer == null) |
| if (peer == null) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| ZLog.Log("Got handshake from client " + peer.m_socket.GetEndPointString()); |
| ZLog.Log("Got handshake from client " + peer.m_socket.GetEndPointString()); |
| this.ClearPlayerData(peer); |
| this.ClearPlayerData(peer); |
| bool flag = !string.IsNullOrEmpty(ZNet.m_serverPassword); |
| bool flag = !string.IsNullOrEmpty(ZNet.m_serverPassword); |
| peer.m_rpc.Invoke("ClientHandshake", new object[] |
| peer.m_rpc.Invoke("ClientHandshake", new object[] |
| { |
| { |
| flag, |
| flag, |
| ZNet.ServerPasswordSalt() |
| ZNet.ServerPasswordSalt() |
| }); |
| }); |
| } |
| } |
| |
| |
| public bool InPasswordDialog() |
| public bool InPasswordDialog() |
| { |
| { |
| return this.m_passwordDialog.gameObject.activeSelf; |
| return this.m_passwordDialog.gameObject.activeSelf; |
| } |
| } |
| |
| |
| private void RPC_ClientHandshake(ZRpc rpc, bool needPassword, string serverPasswordSalt) |
| private void RPC_ClientHandshake(ZRpc rpc, bool needPassword, string serverPasswordSalt) |
| { |
| { |
| this.m_connectingDialog.gameObject.SetActive(false); |
| this.m_connectingDialog.gameObject.SetActive(false); |
| ZNet.m_serverPasswordSalt = serverPasswordSalt; |
| ZNet.m_serverPasswordSalt = serverPasswordSalt; |
| if (needPassword) |
| if (needPassword) |
| { |
| { |
| this.m_passwordDialog.gameObject.SetActive(true); |
| this.m_passwordDialog.gameObject.SetActive(true); |
| GuiInputField componentInChildren = this.m_passwordDialog.GetComponentInChildren<GuiInputField>(); |
| GuiInputField componentInChildren = this.m_passwordDialog.GetComponentInChildren<GuiInputField>(); |
| componentInChildren.text = ""; |
| componentInChildren.text = ""; |
| componentInChildren.ActivateInputField(); |
| componentInChildren.ActivateInputField(); |
| componentInChildren.OnInputSubmit.AddListener(new UnityAction<string>(this.OnPasswordEntered)); |
| componentInChildren.OnInputSubmit.AddListener(new UnityAction<string>(this.OnPasswordEntered)); |
| this.m_tempPasswordRPC = rpc; |
| this.m_tempPasswordRPC = rpc; |
| return; |
| return; |
| } |
| } |
| this.SendPeerInfo(rpc, ""); |
| this.SendPeerInfo(rpc, ""); |
| } |
| } |
| |
| |
| private void OnPasswordEntered(string pwd) |
| private void OnPasswordEntered(string pwd) |
| { |
| { |
| if (!this.m_tempPasswordRPC.IsConnected()) |
| if (!this.m_tempPasswordRPC.IsConnected()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (string.IsNullOrEmpty(pwd)) |
| if (string.IsNullOrEmpty(pwd)) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| this.m_passwordDialog.GetComponentInChildren<GuiInputField>().OnInputSubmit.RemoveListener(new UnityAction<string>(this.OnPasswordEntered)); |
| this.m_passwordDialog.GetComponentInChildren<GuiInputField>().OnInputSubmit.RemoveListener(new UnityAction<string>(this.OnPasswordEntered)); |
| this.m_passwordDialog.gameObject.SetActive(false); |
| this.m_passwordDialog.gameObject.SetActive(false); |
| this.SendPeerInfo(this.m_tempPasswordRPC, pwd); |
| this.SendPeerInfo(this.m_tempPasswordRPC, pwd); |
| this.m_tempPasswordRPC = null; |
| this.m_tempPasswordRPC = null; |
| } |
| } |
| |
| |
| private void SendPeerInfo(ZRpc rpc, string password = "") |
| private void SendPeerInfo(ZRpc rpc, string password = "") |
| { |
| { |
| ZPackage zpackage = new ZPackage(); |
| ZPackage zpackage = new ZPackage(); |
| zpackage.Write(ZNet.GetUID()); |
| zpackage.Write(ZNet.GetUID()); |
| zpackage.Write(global::Version.CurrentVersion.ToString()); |
| zpackage.Write(global::Version.CurrentVersion.ToString()); |
| . | zpackage.Write(23U); |
| zpackage.Write(27U); |
| zpackage.Write(this.m_referencePosition); |
| zpackage.Write(this.m_referencePosition); |
| zpackage.Write(Game.instance.GetPlayerProfile().GetName()); |
| zpackage.Write(Game.instance.GetPlayerProfile().GetName()); |
| if (this.IsServer()) |
| if (this.IsServer()) |
| { |
| { |
| zpackage.Write(ZNet.m_world.m_name); |
| zpackage.Write(ZNet.m_world.m_name); |
| zpackage.Write(ZNet.m_world.m_seed); |
| zpackage.Write(ZNet.m_world.m_seed); |
| zpackage.Write(ZNet.m_world.m_seedName); |
| zpackage.Write(ZNet.m_world.m_seedName); |
| zpackage.Write(ZNet.m_world.m_uid); |
| zpackage.Write(ZNet.m_world.m_uid); |
| zpackage.Write(ZNet.m_world.m_worldGenVersion); |
| zpackage.Write(ZNet.m_world.m_worldGenVersion); |
| zpackage.Write(this.m_netTime); |
| zpackage.Write(this.m_netTime); |
| } |
| } |
| else |
| else |
| { |
| { |
| string text = (string.IsNullOrEmpty(password) ? "" : ZNet.HashPassword(password, ZNet.ServerPasswordSalt())); |
| string text = (string.IsNullOrEmpty(password) ? "" : ZNet.HashPassword(password, ZNet.ServerPasswordSalt())); |
| zpackage.Write(text); |
| zpackage.Write(text); |
| rpc.GetSocket().GetHostName(); |
| rpc.GetSocket().GetHostName(); |
| SteamNetworkingIdentity steamNetworkingIdentity = default(SteamNetworkingIdentity); |
| SteamNetworkingIdentity steamNetworkingIdentity = default(SteamNetworkingIdentity); |
| steamNetworkingIdentity.SetSteamID(new CSteamID(ZNet.m_serverSteamID)); |
| steamNetworkingIdentity.SetSteamID(new CSteamID(ZNet.m_serverSteamID)); |
| byte[] array = ZSteamMatchmaking.instance.RequestSessionTicket(ref steamNetworkingIdentity); |
| byte[] array = ZSteamMatchmaking.instance.RequestSessionTicket(ref steamNetworkingIdentity); |
| if (array == null) |
| if (array == null) |
| { |
| { |
| ZNet.m_connectionStatus = ZNet.ConnectionStatus.ErrorConnectFailed; |
| ZNet.m_connectionStatus = ZNet.ConnectionStatus.ErrorConnectFailed; |
| return; |
| return; |
| } |
| } |
| zpackage.Write(array); |
| zpackage.Write(array); |
| } |
| } |
| rpc.Invoke("PeerInfo", new object[] { zpackage }); |
| rpc.Invoke("PeerInfo", new object[] { zpackage }); |
| } |
| } |
| |
| |
| private void RPC_PeerInfo(ZRpc rpc, ZPackage pkg) |
| private void RPC_PeerInfo(ZRpc rpc, ZPackage pkg) |
| { |
| { |
| ZNetPeer peer = this.GetPeer(rpc); |
| ZNetPeer peer = this.GetPeer(rpc); |
| if (peer == null) |
| if (peer == null) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| long num = pkg.ReadLong(); |
| long num = pkg.ReadLong(); |
| string text = pkg.ReadString(); |
| string text = pkg.ReadString(); |
| uint num2 = 0U; |
| uint num2 = 0U; |
| GameVersion gameVersion; |
| GameVersion gameVersion; |
| if (GameVersion.TryParseGameVersion(text, out gameVersion) && gameVersion >= global::Version.FirstVersionWithNetworkVersion) |
| if (GameVersion.TryParseGameVersion(text, out gameVersion) && gameVersion >= global::Version.FirstVersionWithNetworkVersion) |
| { |
| { |
| num2 = pkg.ReadUInt(); |
| num2 = pkg.ReadUInt(); |
| } |
| } |
| string endPointString = peer.m_socket.GetEndPointString(); |
| string endPointString = peer.m_socket.GetEndPointString(); |
| string hostName = peer.m_socket.GetHostName(); |
| string hostName = peer.m_socket.GetHostName(); |
| . | ZLog.Log("Network version check, their:" + num2.ToString() + ", mine:" + 23U.ToString()); |
| ZLog.Log("Network version check, their:" + num2.ToString() + ", mine:" + 27U.ToString()); |
| if (num2 != 23U) |
| if (num2 != 27U) |
| { |
| { |
| if (ZNet.m_isServer) |
| if (ZNet.m_isServer) |
| { |
| { |
| rpc.Invoke("Error", new object[] { 3 }); |
| rpc.Invoke("Error", new object[] { 3 }); |
| } |
| } |
| else |
| else |
| { |
| { |
| ZNet.m_connectionStatus = ZNet.ConnectionStatus.ErrorVersion; |
| ZNet.m_connectionStatus = ZNet.ConnectionStatus.ErrorVersion; |
| } |
| } |
| string[] array = new string[11]; |
| string[] array = new string[11]; |
| array[0] = "Peer "; |
| array[0] = "Peer "; |
| array[1] = endPointString; |
| array[1] = endPointString; |
| array[2] = " has incompatible version, mine:"; |
| array[2] = " has incompatible version, mine:"; |
| array[3] = global::Version.CurrentVersion.ToString(); |
| array[3] = global::Version.CurrentVersion.ToString(); |
| array[4] = " (network version "; |
| array[4] = " (network version "; |
| . | array[5] = 23U.ToString(); |
| array[5] = 27U.ToString(); |
| array[6] = ") remote "; |
| array[6] = ") remote "; |
| int num3 = 7; |
| int num3 = 7; |
| GameVersion gameVersion2 = gameVersion; |
| GameVersion gameVersion2 = gameVersion; |
| array[num3] = gameVersion2.ToString(); |
| array[num3] = gameVersion2.ToString(); |
| array[8] = " (network version "; |
| array[8] = " (network version "; |
| array[9] = ((num2 == uint.MaxValue) ? "unknown" : num2.ToString()); |
| array[9] = ((num2 == uint.MaxValue) ? "unknown" : num2.ToString()); |
| array[10] = ")"; |
| array[10] = ")"; |
| ZLog.Log(string.Concat(array)); |
| ZLog.Log(string.Concat(array)); |
| return; |
| return; |
| } |
| } |
| Vector3 vector = pkg.ReadVector3(); |
| Vector3 vector = pkg.ReadVector3(); |
| string text2 = pkg.ReadString(); |
| string text2 = pkg.ReadString(); |
| if (ZNet.m_isServer) |
| if (ZNet.m_isServer) |
| { |
| { |
| if (!this.IsAllowed(hostName, text2)) |
| if (!this.IsAllowed(hostName, text2)) |
| { |
| { |
| rpc.Invoke("Error", new object[] { 8 }); |
| rpc.Invoke("Error", new object[] { 8 }); |
| ZLog.Log(string.Concat(new string[] { "Player ", text2, " : ", hostName, " is blacklisted or not in whitelist." })); |
| ZLog.Log(string.Concat(new string[] { "Player ", text2, " : ", hostName, " is blacklisted or not in whitelist." })); |
| return; |
| return; |
| } |
| } |
| string text3 = pkg.ReadString(); |
| string text3 = pkg.ReadString(); |
| if (ZNet.m_onlineBackend == OnlineBackendType.Steamworks) |
| if (ZNet.m_onlineBackend == OnlineBackendType.Steamworks) |
| { |
| { |
| ZSteamSocket zsteamSocket = peer.m_socket as ZSteamSocket; |
| ZSteamSocket zsteamSocket = peer.m_socket as ZSteamSocket; |
| byte[] array2 = pkg.ReadByteArray(); |
| byte[] array2 = pkg.ReadByteArray(); |
| if (!ZSteamMatchmaking.instance.VerifySessionTicket(array2, zsteamSocket.GetPeerID())) |
| if (!ZSteamMatchmaking.instance.VerifySessionTicket(array2, zsteamSocket.GetPeerID())) |
| { |
| { |
| ZLog.Log("Peer " + endPointString + " has invalid session ticket"); |
| ZLog.Log("Peer " + endPointString + " has invalid session ticket"); |
| rpc.Invoke("Error", new object[] { 8 }); |
| rpc.Invoke("Error", new object[] { 8 }); |
| return; |
| return; |
| } |
| } |
| } |
| } |
| if (ZNet.m_onlineBackend == OnlineBackendType.PlayFab) |
| if (ZNet.m_onlineBackend == OnlineBackendType.PlayFab) |
| { |
| { |
| PrivilegeManager.Platform platform; |
| PrivilegeManager.Platform platform; |
| if (!Enum.TryParse<PrivilegeManager.Platform>(peer.m_socket.GetHostName().Split('_', StringSplitOptions.None)[0], out platform)) |
| if (!Enum.TryParse<PrivilegeManager.Platform>(peer.m_socket.GetHostName().Split('_', StringSplitOptions.None)[0], out platform)) |
| { |
| { |
| ZLog.LogError("Failed to parse peer platform! Using \"" + PrivilegeManager.Platform.Unknown.ToString() + "\"."); |
| ZLog.LogError("Failed to parse peer platform! Using \"" + PrivilegeManager.Platform.Unknown.ToString() + "\"."); |
| platform = PrivilegeManager.Platform.Unknown; |
| platform = PrivilegeManager.Platform.Unknown; |
| } |
| } |
| if (!PrivilegeManager.CanCrossplay && PrivilegeManager.GetCurrentPlatform() != platform) |
| if (!PrivilegeManager.CanCrossplay && PrivilegeManager.GetCurrentPlatform() != platform) |
| { |
| { |
| rpc.Invoke("Error", new object[] { 10 }); |
| rpc.Invoke("Error", new object[] { 10 }); |
| ZLog.Log("Peer diconnected due to server platform privileges disallowing crossplay. Server platform: " + PrivilegeManager.GetCurrentPlatform().ToString() + " Peer platform: " + platform.ToString()); |
| ZLog.Log("Peer diconnected due to server platform privileges disallowing crossplay. Server platform: " + PrivilegeManager.GetCurrentPlatform().ToString() + " Peer platform: " + platform.ToString()); |
| return; |
| return; |
| } |
| } |
| } |
| } |
| if (this.GetNrOfPlayers() >= 10) |
| if (this.GetNrOfPlayers() >= 10) |
| { |
| { |
| rpc.Invoke("Error", new object[] { 9 }); |
| rpc.Invoke("Error", new object[] { 9 }); |
| ZLog.Log("Peer " + endPointString + " disconnected due to server is full"); |
| ZLog.Log("Peer " + endPointString + " disconnected due to server is full"); |
| return; |
| return; |
| } |
| } |
| if (ZNet.m_serverPassword != text3) |
| if (ZNet.m_serverPassword != text3) |
| { |
| { |
| rpc.Invoke("Error", new object[] { 6 }); |
| rpc.Invoke("Error", new object[] { 6 }); |
| ZLog.Log("Peer " + endPointString + " has wrong password"); |
| ZLog.Log("Peer " + endPointString + " has wrong password"); |
| return; |
| return; |
| } |
| } |
| if (this.IsConnected(num)) |
| if (this.IsConnected(num)) |
| { |
| { |
| rpc.Invoke("Error", new object[] { 7 }); |
| rpc.Invoke("Error", new object[] { 7 }); |
| ZLog.Log("Already connected to peer with UID:" + num.ToString() + " " + endPointString); |
| ZLog.Log("Already connected to peer with UID:" + num.ToString() + " " + endPointString); |
| return; |
| return; |
| } |
| } |
| } |
| } |
| else |
| else |
| { |
| { |
| ZNet.m_world = new World(); |
| ZNet.m_world = new World(); |
| ZNet.m_world.m_name = pkg.ReadString(); |
| ZNet.m_world.m_name = pkg.ReadString(); |
| ZNet.m_world.m_seed = pkg.ReadInt(); |
| ZNet.m_world.m_seed = pkg.ReadInt(); |
| ZNet.m_world.m_seedName = pkg.ReadString(); |
| ZNet.m_world.m_seedName = pkg.ReadString(); |
| ZNet.m_world.m_uid = pkg.ReadLong(); |
| ZNet.m_world.m_uid = pkg.ReadLong(); |
| ZNet.m_world.m_worldGenVersion = pkg.ReadInt(); |
| ZNet.m_world.m_worldGenVersion = pkg.ReadInt(); |
| WorldGenerator.Initialize(ZNet.m_world); |
| WorldGenerator.Initialize(ZNet.m_world); |
| this.m_netTime = pkg.ReadDouble(); |
| this.m_netTime = pkg.ReadDouble(); |
| } |
| } |
| peer.m_refPos = vector; |
| peer.m_refPos = vector; |
| peer.m_uid = num; |
| peer.m_uid = num; |
| peer.m_playerName = text2; |
| peer.m_playerName = text2; |
| rpc.Register<ZPackage>("ServerSyncedPlayerData", new Action<ZRpc, ZPackage>(this.RPC_ServerSyncedPlayerData)); |
| rpc.Register<ZPackage>("ServerSyncedPlayerData", new Action<ZRpc, ZPackage>(this.RPC_ServerSyncedPlayerData)); |
| rpc.Register<ZPackage>("PlayerList", new Action<ZRpc, ZPackage>(this.RPC_PlayerList)); |
| rpc.Register<ZPackage>("PlayerList", new Action<ZRpc, ZPackage>(this.RPC_PlayerList)); |
| rpc.Register<ZPackage>("AdminList", new Action<ZRpc, ZPackage>(this.RPC_AdminList)); |
| rpc.Register<ZPackage>("AdminList", new Action<ZRpc, ZPackage>(this.RPC_AdminList)); |
| rpc.Register<string>("RemotePrint", new Action<ZRpc, string>(this.RPC_RemotePrint)); |
| rpc.Register<string>("RemotePrint", new Action<ZRpc, string>(this.RPC_RemotePrint)); |
| if (ZNet.m_isServer) |
| if (ZNet.m_isServer) |
| { |
| { |
| rpc.Register<ZDOID>("CharacterID", new Action<ZRpc, ZDOID>(this.RPC_CharacterID)); |
| rpc.Register<ZDOID>("CharacterID", new Action<ZRpc, ZDOID>(this.RPC_CharacterID)); |
| rpc.Register<string>("Kick", new Action<ZRpc, string>(this.RPC_Kick)); |
| rpc.Register<string>("Kick", new Action<ZRpc, string>(this.RPC_Kick)); |
| rpc.Register<string>("Ban", new Action<ZRpc, string>(this.RPC_Ban)); |
| rpc.Register<string>("Ban", new Action<ZRpc, string>(this.RPC_Ban)); |
| rpc.Register<string>("Unban", new Action<ZRpc, string>(this.RPC_Unban)); |
| rpc.Register<string>("Unban", new Action<ZRpc, string>(this.RPC_Unban)); |
| rpc.Register<string>("RPC_RemoteCommand", new Action<ZRpc, string>(this.RPC_RemoteCommand)); |
| rpc.Register<string>("RPC_RemoteCommand", new Action<ZRpc, string>(this.RPC_RemoteCommand)); |
| rpc.Register("Save", new ZRpc.RpcMethod.Method(this.RPC_Save)); |
| rpc.Register("Save", new ZRpc.RpcMethod.Method(this.RPC_Save)); |
| rpc.Register("PrintBanned", new ZRpc.RpcMethod.Method(this.RPC_PrintBanned)); |
| rpc.Register("PrintBanned", new ZRpc.RpcMethod.Method(this.RPC_PrintBanned)); |
| } |
| } |
| else |
| else |
| { |
| { |
| rpc.Register<double>("NetTime", new Action<ZRpc, double>(this.RPC_NetTime)); |
| rpc.Register<double>("NetTime", new Action<ZRpc, double>(this.RPC_NetTime)); |
| } |
| } |
| if (ZNet.m_isServer) |
| if (ZNet.m_isServer) |
| { |
| { |
| this.SendPeerInfo(rpc, ""); |
| this.SendPeerInfo(rpc, ""); |
| peer.m_socket.VersionMatch(); |
| peer.m_socket.VersionMatch(); |
| this.SendPlayerList(); |
| this.SendPlayerList(); |
| this.SendAdminList(); |
| this.SendAdminList(); |
| } |
| } |
| else |
| else |
| { |
| { |
| peer.m_socket.VersionMatch(); |
| peer.m_socket.VersionMatch(); |
| ZNet.m_connectionStatus = ZNet.ConnectionStatus.Connected; |
| ZNet.m_connectionStatus = ZNet.ConnectionStatus.Connected; |
| } |
| } |
| this.m_zdoMan.AddPeer(peer); |
| this.m_zdoMan.AddPeer(peer); |
| this.m_routedRpc.AddPeer(peer); |
| this.m_routedRpc.AddPeer(peer); |
| } |
| } |
| |
| |
| private void SendDisconnect() |
| private void SendDisconnect() |
| { |
| { |
| ZLog.Log("Sending disconnect msg"); |
| ZLog.Log("Sending disconnect msg"); |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| { |
| { |
| this.SendDisconnect(znetPeer); |
| this.SendDisconnect(znetPeer); |
| } |
| } |
| } |
| } |
| |
| |
| private void SendDisconnect(ZNetPeer peer) |
| private void SendDisconnect(ZNetPeer peer) |
| { |
| { |
| if (peer.m_rpc != null) |
| if (peer.m_rpc != null) |
| { |
| { |
| ZLog.Log("Sent to " + peer.m_socket.GetEndPointString()); |
| ZLog.Log("Sent to " + peer.m_socket.GetEndPointString()); |
| peer.m_rpc.Invoke("Disconnect", Array.Empty<object>()); |
| peer.m_rpc.Invoke("Disconnect", Array.Empty<object>()); |
| } |
| } |
| } |
| } |
| |
| |
| private void RPC_Disconnect(ZRpc rpc) |
| private void RPC_Disconnect(ZRpc rpc) |
| { |
| { |
| ZLog.Log("RPC_Disconnect"); |
| ZLog.Log("RPC_Disconnect"); |
| ZNetPeer peer = this.GetPeer(rpc); |
| ZNetPeer peer = this.GetPeer(rpc); |
| if (peer != null) |
| if (peer != null) |
| { |
| { |
| if (peer.m_server) |
| if (peer.m_server) |
| { |
| { |
| ZNet.m_connectionStatus = ZNet.ConnectionStatus.ErrorDisconnected; |
| ZNet.m_connectionStatus = ZNet.ConnectionStatus.ErrorDisconnected; |
| } |
| } |
| this.Disconnect(peer); |
| this.Disconnect(peer); |
| } |
| } |
| } |
| } |
| |
| |
| private void RPC_Error(ZRpc rpc, int error) |
| private void RPC_Error(ZRpc rpc, int error) |
| { |
| { |
| ZNet.ConnectionStatus connectionStatus = (ZNet.ConnectionStatus)error; |
| ZNet.ConnectionStatus connectionStatus = (ZNet.ConnectionStatus)error; |
| ZNet.m_connectionStatus = connectionStatus; |
| ZNet.m_connectionStatus = connectionStatus; |
| ZLog.Log("Got connectoin error msg " + connectionStatus.ToString()); |
| ZLog.Log("Got connectoin error msg " + connectionStatus.ToString()); |
| } |
| } |
| |
| |
| public bool IsConnected(long uid) |
| public bool IsConnected(long uid) |
| { |
| { |
| if (uid == ZNet.GetUID()) |
| if (uid == ZNet.GetUID()) |
| { |
| { |
| return true; |
| return true; |
| } |
| } |
| using (List<ZNetPeer>.Enumerator enumerator = this.m_peers.GetEnumerator()) |
| using (List<ZNetPeer>.Enumerator enumerator = this.m_peers.GetEnumerator()) |
| { |
| { |
| while (enumerator.MoveNext()) |
| while (enumerator.MoveNext()) |
| { |
| { |
| if (enumerator.Current.m_uid == uid) |
| if (enumerator.Current.m_uid == uid) |
| { |
| { |
| return true; |
| return true; |
| } |
| } |
| } |
| } |
| } |
| } |
| return false; |
| return false; |
| } |
| } |
| |
| |
| private void ClearPlayerData(ZNetPeer peer) |
| private void ClearPlayerData(ZNetPeer peer) |
| { |
| { |
| this.m_routedRpc.RemovePeer(peer); |
| this.m_routedRpc.RemovePeer(peer); |
| this.m_zdoMan.RemovePeer(peer); |
| this.m_zdoMan.RemovePeer(peer); |
| } |
| } |
| |
| |
| public void Disconnect(ZNetPeer peer) |
| public void Disconnect(ZNetPeer peer) |
| { |
| { |
| this.ClearPlayerData(peer); |
| this.ClearPlayerData(peer); |
| this.m_peers.Remove(peer); |
| this.m_peers.Remove(peer); |
| peer.Dispose(); |
| peer.Dispose(); |
| if (ZNet.m_isServer) |
| if (ZNet.m_isServer) |
| { |
| { |
| this.SendPlayerList(); |
| this.SendPlayerList(); |
| } |
| } |
| } |
| } |
| |
| |
| private void FixedUpdate() |
| private void FixedUpdate() |
| { |
| { |
| this.UpdateNetTime(Time.fixedDeltaTime); |
| this.UpdateNetTime(Time.fixedDeltaTime); |
| } |
| } |
| |
| |
| private void Update() |
| private void Update() |
| { |
| { |
| float deltaTime = Time.deltaTime; |
| float deltaTime = Time.deltaTime; |
| ZSteamSocket.UpdateAllSockets(deltaTime); |
| ZSteamSocket.UpdateAllSockets(deltaTime); |
| ZPlayFabSocket.UpdateAllSockets(deltaTime); |
| ZPlayFabSocket.UpdateAllSockets(deltaTime); |
| if (this.IsServer()) |
| if (this.IsServer()) |
| { |
| { |
| this.UpdateBanList(deltaTime); |
| this.UpdateBanList(deltaTime); |
| } |
| } |
| this.CheckForIncommingServerConnections(); |
| this.CheckForIncommingServerConnections(); |
| this.UpdatePeers(deltaTime); |
| this.UpdatePeers(deltaTime); |
| this.SendPeriodicData(deltaTime); |
| this.SendPeriodicData(deltaTime); |
| this.m_zdoMan.Update(deltaTime); |
| this.m_zdoMan.Update(deltaTime); |
| this.UpdateSave(); |
| this.UpdateSave(); |
| if (ZNet.PeersToDisconnectAfterKick.Count < 1) |
| if (ZNet.PeersToDisconnectAfterKick.Count < 1) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| foreach (ZNetPeer znetPeer in ZNet.PeersToDisconnectAfterKick.Keys.ToArray<ZNetPeer>()) |
| foreach (ZNetPeer znetPeer in ZNet.PeersToDisconnectAfterKick.Keys.ToArray<ZNetPeer>()) |
| { |
| { |
| if (Time.time >= ZNet.PeersToDisconnectAfterKick[znetPeer]) |
| if (Time.time >= ZNet.PeersToDisconnectAfterKick[znetPeer]) |
| { |
| { |
| this.Disconnect(znetPeer); |
| this.Disconnect(znetPeer); |
| ZNet.PeersToDisconnectAfterKick.Remove(znetPeer); |
| ZNet.PeersToDisconnectAfterKick.Remove(znetPeer); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| private void LateUpdate() |
| private void LateUpdate() |
| { |
| { |
| ZPlayFabSocket.LateUpdateAllSocket(); |
| ZPlayFabSocket.LateUpdateAllSocket(); |
| } |
| } |
| |
| |
| private void UpdateNetTime(float dt) |
| private void UpdateNetTime(float dt) |
| { |
| { |
| if (this.IsServer()) |
| if (this.IsServer()) |
| { |
| { |
| if (this.GetNrOfPlayers() > 0) |
| if (this.GetNrOfPlayers() > 0) |
| { |
| { |
| this.m_netTime += (double)dt; |
| this.m_netTime += (double)dt; |
| return; |
| return; |
| } |
| } |
| } |
| } |
| else |
| else |
| { |
| { |
| this.m_netTime += (double)dt; |
| this.m_netTime += (double)dt; |
| } |
| } |
| } |
| } |
| |
| |
| private void UpdateBanList(float dt) |
| private void UpdateBanList(float dt) |
| { |
| { |
| this.m_banlistTimer += dt; |
| this.m_banlistTimer += dt; |
| if (this.m_banlistTimer > 5f) |
| if (this.m_banlistTimer > 5f) |
| { |
| { |
| this.m_banlistTimer = 0f; |
| this.m_banlistTimer = 0f; |
| this.CheckWhiteList(); |
| this.CheckWhiteList(); |
| foreach (string text in this.m_bannedList.GetList()) |
| foreach (string text in this.m_bannedList.GetList()) |
| { |
| { |
| this.InternalKick(text); |
| this.InternalKick(text); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| private void CheckWhiteList() |
| private void CheckWhiteList() |
| { |
| { |
| if (this.m_permittedList.Count() == 0) |
| if (this.m_permittedList.Count() == 0) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| bool flag = false; |
| bool flag = false; |
| while (!flag) |
| while (!flag) |
| { |
| { |
| flag = true; |
| flag = true; |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| { |
| { |
| if (znetPeer.IsReady()) |
| if (znetPeer.IsReady()) |
| { |
| { |
| string hostName = znetPeer.m_socket.GetHostName(); |
| string hostName = znetPeer.m_socket.GetHostName(); |
| if (!this.ListContainsId(this.m_permittedList, hostName)) |
| if (!this.ListContainsId(this.m_permittedList, hostName)) |
| { |
| { |
| ZLog.Log("Kicking player not in permitted list " + znetPeer.m_playerName + " host: " + hostName); |
| ZLog.Log("Kicking player not in permitted list " + znetPeer.m_playerName + " host: " + hostName); |
| this.InternalKick(znetPeer); |
| this.InternalKick(znetPeer); |
| flag = false; |
| flag = false; |
| break; |
| break; |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| public bool IsSaving() |
| public bool IsSaving() |
| { |
| { |
| return this.m_saveThread != null; |
| return this.m_saveThread != null; |
| } |
| } |
| |
| |
| public void SaveWorldAndPlayerProfiles() |
| public void SaveWorldAndPlayerProfiles() |
| { |
| { |
| if (this.IsServer()) |
| if (this.IsServer()) |
| { |
| { |
| this.RPC_Save(null); |
| this.RPC_Save(null); |
| return; |
| return; |
| } |
| } |
| ZRpc serverRPC = this.GetServerRPC(); |
| ZRpc serverRPC = this.GetServerRPC(); |
| if (serverRPC != null) |
| if (serverRPC != null) |
| { |
| { |
| serverRPC.Invoke("Save", Array.Empty<object>()); |
| serverRPC.Invoke("Save", Array.Empty<object>()); |
| } |
| } |
| } |
| } |
| |
| |
| private void RPC_Save(ZRpc rpc) |
| private void RPC_Save(ZRpc rpc) |
| { |
| { |
| if (!base.enabled) |
| if (!base.enabled) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (rpc != null && !this.ListContainsId(this.m_adminList, rpc.GetSocket().GetHostName())) |
| if (rpc != null && !this.ListContainsId(this.m_adminList, rpc.GetSocket().GetHostName())) |
| { |
| { |
| this.RemotePrint(rpc, "You are not admin"); |
| this.RemotePrint(rpc, "You are not admin"); |
| return; |
| return; |
| } |
| } |
| bool flag; |
| bool flag; |
| if (!this.EnoughDiskSpaceAvailable(out flag, false, null)) |
| if (!this.EnoughDiskSpaceAvailable(out flag, false, null)) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| this.RemotePrint(rpc, "Saving.."); |
| this.RemotePrint(rpc, "Saving.."); |
| Game.instance.SavePlayerProfile(true); |
| Game.instance.SavePlayerProfile(true); |
| this.Save(false, true); |
| this.Save(false, true); |
| } |
| } |
| |
| |
| private bool ListContainsId(SyncedList list, string id) |
| private bool ListContainsId(SyncedList list, string id) |
| { |
| { |
| if (id.StartsWith(PrivilegeManager.GetPlatformPrefix(PrivilegeManager.Platform.Steam))) |
| if (id.StartsWith(PrivilegeManager.GetPlatformPrefix(PrivilegeManager.Platform.Steam))) |
| { |
| { |
| return list.Contains(id) || list.Contains(id.Substring(PrivilegeManager.GetPlatformPrefix(PrivilegeManager.Platform.Steam).Length)); |
| return list.Contains(id) || list.Contains(id.Substring(PrivilegeManager.GetPlatformPrefix(PrivilegeManager.Platform.Steam).Length)); |
| } |
| } |
| if (!id.Contains("_")) |
| if (!id.Contains("_")) |
| { |
| { |
| return list.Contains(PrivilegeManager.GetPlatformPrefix(PrivilegeManager.Platform.Steam) + id) || list.Contains(id); |
| return list.Contains(PrivilegeManager.GetPlatformPrefix(PrivilegeManager.Platform.Steam) + id) || list.Contains(id); |
| } |
| } |
| return list.Contains(id); |
| return list.Contains(id); |
| } |
| } |
| |
| |
| public void Save(bool sync, bool saveOtherPlayerProfiles = false) |
| public void Save(bool sync, bool saveOtherPlayerProfiles = false) |
| { |
| { |
| Game.instance.m_saveTimer = 0f; |
| Game.instance.m_saveTimer = 0f; |
| if (ZNet.m_loadError || ZoneSystem.instance.SkipSaving() || DungeonDB.instance.SkipSaving()) |
| if (ZNet.m_loadError || ZoneSystem.instance.SkipSaving() || DungeonDB.instance.SkipSaving()) |
| { |
| { |
| ZLog.LogWarning("Skipping world save"); |
| ZLog.LogWarning("Skipping world save"); |
| return; |
| return; |
| } |
| } |
| if (ZNet.m_isServer && ZNet.m_world != null) |
| if (ZNet.m_isServer && ZNet.m_world != null) |
| { |
| { |
| if (saveOtherPlayerProfiles) |
| if (saveOtherPlayerProfiles) |
| { |
| { |
| this.SaveOtherPlayerProfiles(); |
| this.SaveOtherPlayerProfiles(); |
| } |
| } |
| this.SaveWorld(sync); |
| this.SaveWorld(sync); |
| } |
| } |
| } |
| } |
| |
| |
| public bool EnoughDiskSpaceAvailable(out bool exitGamePopupShown, bool exitGamePrompt = false, Action<bool> onDecisionMade = null) |
| public bool EnoughDiskSpaceAvailable(out bool exitGamePopupShown, bool exitGamePrompt = false, Action<bool> onDecisionMade = null) |
| { |
| { |
| exitGamePopupShown = false; |
| exitGamePopupShown = false; |
| string text = ""; |
| string text = ""; |
| World worldIfIsHost = ZNet.GetWorldIfIsHost(); |
| World worldIfIsHost = ZNet.GetWorldIfIsHost(); |
| FileHelpers.FileSource fileSource = FileHelpers.FileSource.Cloud; |
| FileHelpers.FileSource fileSource = FileHelpers.FileSource.Cloud; |
| if (worldIfIsHost != null) |
| if (worldIfIsHost != null) |
| { |
| { |
| text = worldIfIsHost.GetDBPath(); |
| text = worldIfIsHost.GetDBPath(); |
| fileSource = worldIfIsHost.m_fileSource; |
| fileSource = worldIfIsHost.m_fileSource; |
| } |
| } |
| PlayerProfile playerProfile = Game.instance.GetPlayerProfile(); |
| PlayerProfile playerProfile = Game.instance.GetPlayerProfile(); |
| ulong num; |
| ulong num; |
| ulong num2; |
| ulong num2; |
| ulong num3; |
| ulong num3; |
| FileHelpers.CheckDiskSpace(text, playerProfile.GetPath(), fileSource, playerProfile.m_fileSource, out num, out num2, out num3); |
| FileHelpers.CheckDiskSpace(text, playerProfile.GetPath(), fileSource, playerProfile.m_fileSource, out num, out num2, out num3); |
| if (num <= num3 || num <= num2) |
| if (num <= num3 || num <= num2) |
| { |
| { |
| this.LowDiskLeftInformer(num, num2, num3, exitGamePrompt, onDecisionMade); |
| this.LowDiskLeftInformer(num, num2, num3, exitGamePrompt, onDecisionMade); |
| } |
| } |
| if (num <= num3) |
| if (num <= num3) |
| { |
| { |
| if (exitGamePrompt) |
| if (exitGamePrompt) |
| { |
| { |
| exitGamePopupShown = true; |
| exitGamePopupShown = true; |
| } |
| } |
| ZLog.LogWarning("Not enough space left to save. "); |
| ZLog.LogWarning("Not enough space left to save. "); |
| return false; |
| return false; |
| } |
| } |
| return true; |
| return true; |
| } |
| } |
| |
| |
| private void LowDiskLeftInformer(ulong availableFreeSpace, ulong byteLimitWarning, ulong byteLimitBlock, bool exitGamePrompt, Action<bool> onDecisionMade) |
| private void LowDiskLeftInformer(ulong availableFreeSpace, ulong byteLimitWarning, ulong byteLimitBlock, bool exitGamePrompt, Action<bool> onDecisionMade) |
| { |
| { |
| if (availableFreeSpace <= byteLimitBlock) |
| if (availableFreeSpace <= byteLimitBlock) |
| { |
| { |
| if (this.IsDedicated()) |
| if (this.IsDedicated()) |
| { |
| { |
| MessageHud.instance.MessageAll(MessageHud.MessageType.Center, "$msg_worldsaveblockedonserver"); |
| MessageHud.instance.MessageAll(MessageHud.MessageType.Center, "$msg_worldsaveblockedonserver"); |
| } |
| } |
| else if (exitGamePrompt) |
| else if (exitGamePrompt) |
| { |
| { |
| string text = "$menu_lowdisk_block_exitanyway_prompt"; |
| string text = "$menu_lowdisk_block_exitanyway_prompt"; |
| UnifiedPopup.Push(new YesNoPopup("$menu_lowdisk_block_exitanyway_header", text, delegate |
| UnifiedPopup.Push(new YesNoPopup("$menu_lowdisk_block_exitanyway_header", text, delegate |
| { |
| { |
| Action<bool> onDecisionMade2 = onDecisionMade; |
| Action<bool> onDecisionMade2 = onDecisionMade; |
| if (onDecisionMade2 != null) |
| if (onDecisionMade2 != null) |
| { |
| { |
| onDecisionMade2(true); |
| onDecisionMade2(true); |
| } |
| } |
| UnifiedPopup.Pop(); |
| UnifiedPopup.Pop(); |
| }, delegate |
| }, delegate |
| { |
| { |
| Action<bool> onDecisionMade3 = onDecisionMade; |
| Action<bool> onDecisionMade3 = onDecisionMade; |
| if (onDecisionMade3 != null) |
| if (onDecisionMade3 != null) |
| { |
| { |
| onDecisionMade3(false); |
| onDecisionMade3(false); |
| } |
| } |
| UnifiedPopup.Pop(); |
| UnifiedPopup.Pop(); |
| }, true)); |
| }, true)); |
| } |
| } |
| else |
| else |
| { |
| { |
| this.SavingBlockedPopup(); |
| this.SavingBlockedPopup(); |
| } |
| } |
| } |
| } |
| else if (this.IsDedicated()) |
| else if (this.IsDedicated()) |
| { |
| { |
| MessageHud.instance.MessageAll(MessageHud.MessageType.Center, "$msg_worldsavewarningonserver"); |
| MessageHud.instance.MessageAll(MessageHud.MessageType.Center, "$msg_worldsavewarningonserver"); |
| } |
| } |
| else |
| else |
| { |
| { |
| this.SaveLowDiskWarningPopup(); |
| this.SaveLowDiskWarningPopup(); |
| } |
| } |
| ZLog.LogWarning(string.Format("Running low on disk space... Available space: {0} bytes.", availableFreeSpace)); |
| ZLog.LogWarning(string.Format("Running low on disk space... Available space: {0} bytes.", availableFreeSpace)); |
| } |
| } |
| |
| |
| private void SavingBlockedPopup() |
| private void SavingBlockedPopup() |
| { |
| { |
| string text = "$menu_lowdisk_message_block"; |
| string text = "$menu_lowdisk_message_block"; |
| UnifiedPopup.Push(new WarningPopup("$menu_lowdisk_header_block", text, delegate |
| UnifiedPopup.Push(new WarningPopup("$menu_lowdisk_header_block", text, delegate |
| { |
| { |
| UnifiedPopup.Pop(); |
| UnifiedPopup.Pop(); |
| }, true)); |
| }, true)); |
| } |
| } |
| |
| |
| private void SaveLowDiskWarningPopup() |
| private void SaveLowDiskWarningPopup() |
| { |
| { |
| string text = "$menu_lowdisk_message_warn"; |
| string text = "$menu_lowdisk_message_warn"; |
| UnifiedPopup.Push(new WarningPopup("$menu_lowdisk_header_warn", text, delegate |
| UnifiedPopup.Push(new WarningPopup("$menu_lowdisk_header_warn", text, delegate |
| { |
| { |
| UnifiedPopup.Pop(); |
| UnifiedPopup.Pop(); |
| }, true)); |
| }, true)); |
| } |
| } |
| |
| |
| public bool PlayerIsHost |
| public bool PlayerIsHost |
| { |
| { |
| get |
| get |
| { |
| { |
| return ZNet.instance.GetServerPeer() == null; |
| return ZNet.instance.GetServerPeer() == null; |
| } |
| } |
| } |
| } |
| |
| |
| public bool LocalPlayerIsAdminOrHost() |
| public bool LocalPlayerIsAdminOrHost() |
| { |
| { |
| if (this.PlayerIsHost) |
| if (this.PlayerIsHost) |
| { |
| { |
| return true; |
| return true; |
| } |
| } |
| string networkUserId = UserInfo.GetLocalUser().NetworkUserId; |
| string networkUserId = UserInfo.GetLocalUser().NetworkUserId; |
| return this.PlayerIsAdmin(networkUserId); |
| return this.PlayerIsAdmin(networkUserId); |
| } |
| } |
| |
| |
| public bool PlayerIsAdmin(string networkUserId) |
| public bool PlayerIsAdmin(string networkUserId) |
| { |
| { |
| List<string> adminList = this.GetAdminList(); |
| List<string> adminList = this.GetAdminList(); |
| return !string.IsNullOrEmpty(networkUserId) && adminList != null && adminList.Contains(networkUserId); |
| return !string.IsNullOrEmpty(networkUserId) && adminList != null && adminList.Contains(networkUserId); |
| } |
| } |
| |
| |
| public static World GetWorldIfIsHost() |
| public static World GetWorldIfIsHost() |
| { |
| { |
| Debug.Log(string.Format("Am I Host? {0}", ZNet.m_isServer)); |
| Debug.Log(string.Format("Am I Host? {0}", ZNet.m_isServer)); |
| if (ZNet.m_isServer) |
| if (ZNet.m_isServer) |
| { |
| { |
| return ZNet.m_world; |
| return ZNet.m_world; |
| } |
| } |
| return null; |
| return null; |
| } |
| } |
| |
| |
| private void SendPeriodicData(float dt) |
| private void SendPeriodicData(float dt) |
| { |
| { |
| this.m_periodicSendTimer += dt; |
| this.m_periodicSendTimer += dt; |
| if (this.m_periodicSendTimer >= 2f) |
| if (this.m_periodicSendTimer >= 2f) |
| { |
| { |
| this.m_periodicSendTimer = 0f; |
| this.m_periodicSendTimer = 0f; |
| if (this.IsServer()) |
| if (this.IsServer()) |
| { |
| { |
| this.SendNetTime(); |
| this.SendNetTime(); |
| this.SendPlayerList(); |
| this.SendPlayerList(); |
| return; |
| return; |
| } |
| } |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| { |
| { |
| if (znetPeer.IsReady()) |
| if (znetPeer.IsReady()) |
| { |
| { |
| this.SendServerSyncPlayerData(znetPeer); |
| this.SendServerSyncPlayerData(znetPeer); |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| private void SendServerSyncPlayerData(ZNetPeer peer) |
| private void SendServerSyncPlayerData(ZNetPeer peer) |
| { |
| { |
| ZPackage zpackage = new ZPackage(); |
| ZPackage zpackage = new ZPackage(); |
| zpackage.Write(this.m_referencePosition); |
| zpackage.Write(this.m_referencePosition); |
| zpackage.Write(this.m_publicReferencePosition); |
| zpackage.Write(this.m_publicReferencePosition); |
| zpackage.Write(this.m_serverSyncedPlayerData.Count); |
| zpackage.Write(this.m_serverSyncedPlayerData.Count); |
| foreach (KeyValuePair<string, string> keyValuePair in this.m_serverSyncedPlayerData) |
| foreach (KeyValuePair<string, string> keyValuePair in this.m_serverSyncedPlayerData) |
| { |
| { |
| zpackage.Write(keyValuePair.Key); |
| zpackage.Write(keyValuePair.Key); |
| zpackage.Write(keyValuePair.Value); |
| zpackage.Write(keyValuePair.Value); |
| } |
| } |
| peer.m_rpc.Invoke("ServerSyncedPlayerData", new object[] { zpackage }); |
| peer.m_rpc.Invoke("ServerSyncedPlayerData", new object[] { zpackage }); |
| } |
| } |
| |
| |
| private void SendNetTime() |
| private void SendNetTime() |
| { |
| { |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| { |
| { |
| if (znetPeer.IsReady()) |
| if (znetPeer.IsReady()) |
| { |
| { |
| znetPeer.m_rpc.Invoke("NetTime", new object[] { this.m_netTime }); |
| znetPeer.m_rpc.Invoke("NetTime", new object[] { this.m_netTime }); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| private void RPC_NetTime(ZRpc rpc, double time) |
| private void RPC_NetTime(ZRpc rpc, double time) |
| { |
| { |
| this.m_netTime = time; |
| this.m_netTime = time; |
| } |
| } |
| |
| |
| private void RPC_ServerSyncedPlayerData(ZRpc rpc, ZPackage data) |
| private void RPC_ServerSyncedPlayerData(ZRpc rpc, ZPackage data) |
| { |
| { |
| . | |
| RandEventSystem.SetRandomEventsNeedsRefresh(); |
| ZNetPeer peer = this.GetPeer(rpc); |
| ZNetPeer peer = this.GetPeer(rpc); |
| if (peer != null) |
| if (peer != null) |
| { |
| { |
| peer.m_refPos = data.ReadVector3(); |
| peer.m_refPos = data.ReadVector3(); |
| peer.m_publicRefPos = data.ReadBool(); |
| peer.m_publicRefPos = data.ReadBool(); |
| peer.m_serverSyncedPlayerData.Clear(); |
| peer.m_serverSyncedPlayerData.Clear(); |
| int num = data.ReadInt(); |
| int num = data.ReadInt(); |
| for (int i = 0; i < num; i++) |
| for (int i = 0; i < num; i++) |
| { |
| { |
| peer.m_serverSyncedPlayerData.Add(data.ReadString(), data.ReadString()); |
| peer.m_serverSyncedPlayerData.Add(data.ReadString(), data.ReadString()); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| private void UpdatePeers(float dt) |
| private void UpdatePeers(float dt) |
| { |
| { |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| { |
| { |
| if (!znetPeer.m_rpc.IsConnected()) |
| if (!znetPeer.m_rpc.IsConnected()) |
| { |
| { |
| if (znetPeer.m_server) |
| if (znetPeer.m_server) |
| { |
| { |
| if (ZNet.m_externalError != ZNet.ConnectionStatus.None) |
| if (ZNet.m_externalError != ZNet.ConnectionStatus.None) |
| { |
| { |
| ZNet.m_connectionStatus = ZNet.m_externalError; |
| ZNet.m_connectionStatus = ZNet.m_externalError; |
| } |
| } |
| else if (ZNet.m_connectionStatus == ZNet.ConnectionStatus.Connecting) |
| else if (ZNet.m_connectionStatus == ZNet.ConnectionStatus.Connecting) |
| { |
| { |
| ZNet.m_connectionStatus = ZNet.ConnectionStatus.ErrorConnectFailed; |
| ZNet.m_connectionStatus = ZNet.ConnectionStatus.ErrorConnectFailed; |
| } |
| } |
| else |
| else |
| { |
| { |
| ZNet.m_connectionStatus = ZNet.ConnectionStatus.ErrorDisconnected; |
| ZNet.m_connectionStatus = ZNet.ConnectionStatus.ErrorDisconnected; |
| } |
| } |
| } |
| } |
| this.Disconnect(znetPeer); |
| this.Disconnect(znetPeer); |
| break; |
| break; |
| } |
| } |
| } |
| } |
| ZNetPeer[] array = this.m_peers.ToArray(); |
| ZNetPeer[] array = this.m_peers.ToArray(); |
| for (int i = 0; i < array.Length; i++) |
| for (int i = 0; i < array.Length; i++) |
| { |
| { |
| if (array[i].m_rpc.Update(dt) == ZRpc.ErrorCode.IncompatibleVersion) |
| if (array[i].m_rpc.Update(dt) == ZRpc.ErrorCode.IncompatibleVersion) |
| { |
| { |
| ZNet.m_connectionStatus = ZNet.ConnectionStatus.ErrorVersion; |
| ZNet.m_connectionStatus = ZNet.ConnectionStatus.ErrorVersion; |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| private void CheckForIncommingServerConnections() |
| private void CheckForIncommingServerConnections() |
| { |
| { |
| if (this.m_hostSocket == null) |
| if (this.m_hostSocket == null) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| ISocket socket = this.m_hostSocket.Accept(); |
| ISocket socket = this.m_hostSocket.Accept(); |
| if (socket != null) |
| if (socket != null) |
| { |
| { |
| if (!socket.IsConnected()) |
| if (!socket.IsConnected()) |
| { |
| { |
| socket.Dispose(); |
| socket.Dispose(); |
| return; |
| return; |
| } |
| } |
| ZNetPeer znetPeer = new ZNetPeer(socket, false); |
| ZNetPeer znetPeer = new ZNetPeer(socket, false); |
| this.OnNewConnection(znetPeer); |
| this.OnNewConnection(znetPeer); |
| } |
| } |
| } |
| } |
| |
| |
| public ZNetPeer GetPeerByPlayerName(string name) |
| public ZNetPeer GetPeerByPlayerName(string name) |
| { |
| { |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| { |
| { |
| if (znetPeer.IsReady() && znetPeer.m_playerName == name) |
| if (znetPeer.IsReady() && znetPeer.m_playerName == name) |
| { |
| { |
| return znetPeer; |
| return znetPeer; |
| } |
| } |
| } |
| } |
| return null; |
| return null; |
| } |
| } |
| |
| |
| public ZNetPeer GetPeerByHostName(string endpoint) |
| public ZNetPeer GetPeerByHostName(string endpoint) |
| { |
| { |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| { |
| { |
| if (znetPeer.IsReady() && znetPeer.m_socket.GetHostName() == endpoint) |
| if (znetPeer.IsReady() && znetPeer.m_socket.GetHostName() == endpoint) |
| { |
| { |
| return znetPeer; |
| return znetPeer; |
| } |
| } |
| } |
| } |
| return null; |
| return null; |
| } |
| } |
| |
| |
| public ZNetPeer GetPeer(long uid) |
| public ZNetPeer GetPeer(long uid) |
| { |
| { |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| { |
| { |
| if (znetPeer.m_uid == uid) |
| if (znetPeer.m_uid == uid) |
| { |
| { |
| return znetPeer; |
| return znetPeer; |
| } |
| } |
| } |
| } |
| return null; |
| return null; |
| } |
| } |
| |
| |
| private ZNetPeer GetPeer(ZRpc rpc) |
| private ZNetPeer GetPeer(ZRpc rpc) |
| { |
| { |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| { |
| { |
| if (znetPeer.m_rpc == rpc) |
| if (znetPeer.m_rpc == rpc) |
| { |
| { |
| return znetPeer; |
| return znetPeer; |
| } |
| } |
| } |
| } |
| return null; |
| return null; |
| } |
| } |
| |
| |
| public List<ZNetPeer> GetConnectedPeers() |
| public List<ZNetPeer> GetConnectedPeers() |
| { |
| { |
| return new List<ZNetPeer>(this.m_peers); |
| return new List<ZNetPeer>(this.m_peers); |
| } |
| } |
| |
| |
| private void SaveWorld(bool sync) |
| private void SaveWorld(bool sync) |
| { |
| { |
| Action worldSaveStarted = ZNet.WorldSaveStarted; |
| Action worldSaveStarted = ZNet.WorldSaveStarted; |
| if (worldSaveStarted != null) |
| if (worldSaveStarted != null) |
| { |
| { |
| worldSaveStarted(); |
| worldSaveStarted(); |
| } |
| } |
| if (this.m_saveThread != null && this.m_saveThread.IsAlive) |
| if (this.m_saveThread != null && this.m_saveThread.IsAlive) |
| { |
| { |
| this.m_saveThread.Join(); |
| this.m_saveThread.Join(); |
| this.m_saveThread = null; |
| this.m_saveThread = null; |
| } |
| } |
| this.m_saveStartTime = Time.realtimeSinceStartup; |
| this.m_saveStartTime = Time.realtimeSinceStartup; |
| this.m_zdoMan.PrepareSave(); |
| this.m_zdoMan.PrepareSave(); |
| ZoneSystem.instance.PrepareSave(); |
| ZoneSystem.instance.PrepareSave(); |
| RandEventSystem.instance.PrepareSave(); |
| RandEventSystem.instance.PrepareSave(); |
| ZNet.m_backupCount = PlatformPrefs.GetInt("AutoBackups", ZNet.m_backupCount); |
| ZNet.m_backupCount = PlatformPrefs.GetInt("AutoBackups", ZNet.m_backupCount); |
| this.m_saveThreadStartTime = Time.realtimeSinceStartup; |
| this.m_saveThreadStartTime = Time.realtimeSinceStartup; |
| this.m_saveThread = new Thread(new ThreadStart(this.SaveWorldThread)); |
| this.m_saveThread = new Thread(new ThreadStart(this.SaveWorldThread)); |
| this.m_saveThread.Start(); |
| this.m_saveThread.Start(); |
| if (sync) |
| if (sync) |
| { |
| { |
| this.m_saveThread.Join(); |
| this.m_saveThread.Join(); |
| this.m_saveThread = null; |
| this.m_saveThread = null; |
| this.m_sendSaveMessage = 0.5f; |
| this.m_sendSaveMessage = 0.5f; |
| } |
| } |
| } |
| } |
| |
| |
| private void UpdateSave() |
| private void UpdateSave() |
| { |
| { |
| if (this.m_sendSaveMessage > 0f) |
| if (this.m_sendSaveMessage > 0f) |
| { |
| { |
| this.m_sendSaveMessage -= Time.fixedDeltaTime; |
| this.m_sendSaveMessage -= Time.fixedDeltaTime; |
| if (this.m_sendSaveMessage < 0f) |
| if (this.m_sendSaveMessage < 0f) |
| { |
| { |
| this.PrintWorldSaveMessage(); |
| this.PrintWorldSaveMessage(); |
| this.m_sendSaveMessage = 0f; |
| this.m_sendSaveMessage = 0f; |
| } |
| } |
| } |
| } |
| if (this.m_saveThread != null && !this.m_saveThread.IsAlive) |
| if (this.m_saveThread != null && !this.m_saveThread.IsAlive) |
| { |
| { |
| this.m_saveThread = null; |
| this.m_saveThread = null; |
| this.m_sendSaveMessage = 0.5f; |
| this.m_sendSaveMessage = 0.5f; |
| } |
| } |
| } |
| } |
| |
| |
| private void PrintWorldSaveMessage() |
| private void PrintWorldSaveMessage() |
| { |
| { |
| float num = this.m_saveThreadStartTime - this.m_saveStartTime; |
| float num = this.m_saveThreadStartTime - this.m_saveStartTime; |
| float num2 = Time.realtimeSinceStartup - this.m_saveThreadStartTime; |
| float num2 = Time.realtimeSinceStartup - this.m_saveThreadStartTime; |
| if (this.m_saveExceededCloudQuota) |
| if (this.m_saveExceededCloudQuota) |
| { |
| { |
| this.m_saveExceededCloudQuota = false; |
| this.m_saveExceededCloudQuota = false; |
| MessageHud.instance.MessageAll(MessageHud.MessageType.TopLeft, string.Concat(new string[] |
| MessageHud.instance.MessageAll(MessageHud.MessageType.TopLeft, string.Concat(new string[] |
| { |
| { |
| "$msg_worldsavedcloudstoragefull ( ", |
| "$msg_worldsavedcloudstoragefull ( ", |
| num.ToString("0.00"), |
| num.ToString("0.00"), |
| "+", |
| "+", |
| num2.ToString("0.00"), |
| num2.ToString("0.00"), |
| "s )" |
| "s )" |
| })); |
| })); |
| } |
| } |
| else |
| else |
| { |
| { |
| MessageHud.instance.MessageAll(MessageHud.MessageType.TopLeft, string.Concat(new string[] |
| MessageHud.instance.MessageAll(MessageHud.MessageType.TopLeft, string.Concat(new string[] |
| { |
| { |
| "$msg_worldsaved ( ", |
| "$msg_worldsaved ( ", |
| num.ToString("0.00"), |
| num.ToString("0.00"), |
| "+", |
| "+", |
| num2.ToString("0.00"), |
| num2.ToString("0.00"), |
| "s )" |
| "s )" |
| })); |
| })); |
| } |
| } |
| Action worldSaveFinished = ZNet.WorldSaveFinished; |
| Action worldSaveFinished = ZNet.WorldSaveFinished; |
| if (worldSaveFinished == null) |
| if (worldSaveFinished == null) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| worldSaveFinished(); |
| worldSaveFinished(); |
| } |
| } |
| |
| |
| private void SaveWorldThread() |
| private void SaveWorldThread() |
| { |
| { |
| DateTime now = DateTime.Now; |
| DateTime now = DateTime.Now; |
| try |
| try |
| { |
| { |
| ulong num = 52428800UL; |
| ulong num = 52428800UL; |
| num += FileHelpers.GetFileSize(ZNet.m_world.GetMetaPath(), ZNet.m_world.m_fileSource); |
| num += FileHelpers.GetFileSize(ZNet.m_world.GetMetaPath(), ZNet.m_world.m_fileSource); |
| if (FileHelpers.Exists(ZNet.m_world.GetDBPath(), ZNet.m_world.m_fileSource)) |
| if (FileHelpers.Exists(ZNet.m_world.GetDBPath(), ZNet.m_world.m_fileSource)) |
| { |
| { |
| num += FileHelpers.GetFileSize(ZNet.m_world.GetDBPath(), ZNet.m_world.m_fileSource); |
| num += FileHelpers.GetFileSize(ZNet.m_world.GetDBPath(), ZNet.m_world.m_fileSource); |
| } |
| } |
| bool flag = SaveSystem.CheckMove(ZNet.m_world.m_fileName, SaveDataType.World, ref ZNet.m_world.m_fileSource, now, num, false); |
| bool flag = SaveSystem.CheckMove(ZNet.m_world.m_fileName, SaveDataType.World, ref ZNet.m_world.m_fileSource, now, num, false); |
| bool flag2 = ZNet.m_world.m_createBackupBeforeSaving && !flag; |
| bool flag2 = ZNet.m_world.m_createBackupBeforeSaving && !flag; |
| if (FileHelpers.m_cloudEnabled && ZNet.m_world.m_fileSource == FileHelpers.FileSource.Cloud) |
| if (FileHelpers.m_cloudEnabled && ZNet.m_world.m_fileSource == FileHelpers.FileSource.Cloud) |
| { |
| { |
| num *= (flag2 ? 3UL : 2UL); |
| num *= (flag2 ? 3UL : 2UL); |
| if (FileHelpers.OperationExceedsCloudCapacity(num)) |
| if (FileHelpers.OperationExceedsCloudCapacity(num)) |
| { |
| { |
| if (FileHelpers.m_cloudOnly) |
| if (FileHelpers.m_cloudOnly) |
| { |
| { |
| throw new Exception("The world save operation may exceed the cloud save quota and was therefore not performed!"); |
| throw new Exception("The world save operation may exceed the cloud save quota and was therefore not performed!"); |
| } |
| } |
| string metaPath = ZNet.m_world.GetMetaPath(); |
| string metaPath = ZNet.m_world.GetMetaPath(); |
| string dbpath = ZNet.m_world.GetDBPath(); |
| string dbpath = ZNet.m_world.GetDBPath(); |
| ZNet.m_world.m_fileSource = FileHelpers.FileSource.Local; |
| ZNet.m_world.m_fileSource = FileHelpers.FileSource.Local; |
| string metaPath2 = ZNet.m_world.GetMetaPath(); |
| string metaPath2 = ZNet.m_world.GetMetaPath(); |
| string dbpath2 = ZNet.m_world.GetDBPath(); |
| string dbpath2 = ZNet.m_world.GetDBPath(); |
| FileHelpers.FileCopyOutFromCloud(metaPath, metaPath2, true); |
| FileHelpers.FileCopyOutFromCloud(metaPath, metaPath2, true); |
| if (FileHelpers.FileExistsCloud(dbpath)) |
| if (FileHelpers.FileExistsCloud(dbpath)) |
| { |
| { |
| FileHelpers.FileCopyOutFromCloud(dbpath, dbpath2, true); |
| FileHelpers.FileCopyOutFromCloud(dbpath, dbpath2, true); |
| } |
| } |
| SaveSystem.InvalidateCache(); |
| SaveSystem.InvalidateCache(); |
| ZLog.LogWarning("The world save operation may exceed the cloud save quota and it has therefore been moved to local storage!"); |
| ZLog.LogWarning("The world save operation may exceed the cloud save quota and it has therefore been moved to local storage!"); |
| this.m_saveExceededCloudQuota = true; |
| this.m_saveExceededCloudQuota = true; |
| } |
| } |
| } |
| } |
| if (flag2) |
| if (flag2) |
| { |
| { |
| SaveWithBackups saveWithBackups; |
| SaveWithBackups saveWithBackups; |
| if (SaveSystem.TryGetSaveByName(ZNet.m_world.m_fileName, SaveDataType.World, out saveWithBackups) && !saveWithBackups.IsDeleted) |
| if (SaveSystem.TryGetSaveByName(ZNet.m_world.m_fileName, SaveDataType.World, out saveWithBackups) && !saveWithBackups.IsDeleted) |
| { |
| { |
| if (SaveSystem.CreateBackup(saveWithBackups.PrimaryFile, DateTime.Now, ZNet.m_world.m_fileSource)) |
| if (SaveSystem.CreateBackup(saveWithBackups.PrimaryFile, DateTime.Now, ZNet.m_world.m_fileSource)) |
| { |
| { |
| ZLog.Log("Migrating world save from an old save format, created backup!"); |
| ZLog.Log("Migrating world save from an old save format, created backup!"); |
| } |
| } |
| else |
| else |
| { |
| { |
| ZLog.LogError("Failed to create backup of world save " + ZNet.m_world.m_fileName + "!"); |
| ZLog.LogError("Failed to create backup of world save " + ZNet.m_world.m_fileName + "!"); |
| } |
| } |
| } |
| } |
| else |
| else |
| { |
| { |
| ZLog.LogError("Failed to get world save " + ZNet.m_world.m_fileName + " from save system, so a backup couldn't be created!"); |
| ZLog.LogError("Failed to get world save " + ZNet.m_world.m_fileName + " from save system, so a backup couldn't be created!"); |
| } |
| } |
| } |
| } |
| ZNet.m_world.m_createBackupBeforeSaving = false; |
| ZNet.m_world.m_createBackupBeforeSaving = false; |
| DateTime dateTime = DateTime.Now; |
| DateTime dateTime = DateTime.Now; |
| bool flag3 = ZNet.m_world.m_fileSource != FileHelpers.FileSource.Cloud; |
| bool flag3 = ZNet.m_world.m_fileSource != FileHelpers.FileSource.Cloud; |
| string dbpath3 = ZNet.m_world.GetDBPath(); |
| string dbpath3 = ZNet.m_world.GetDBPath(); |
| string text = (flag3 ? (dbpath3 + ".new") : dbpath3); |
| string text = (flag3 ? (dbpath3 + ".new") : dbpath3); |
| string text2 = dbpath3 + ".old"; |
| string text2 = dbpath3 + ".old"; |
| ZLog.Log("World save writing starting"); |
| ZLog.Log("World save writing starting"); |
| FileWriter fileWriter = new FileWriter(text, FileHelpers.FileHelperType.Binary, ZNet.m_world.m_fileSource); |
| FileWriter fileWriter = new FileWriter(text, FileHelpers.FileHelperType.Binary, ZNet.m_world.m_fileSource); |
| ZLog.Log("World save writing started"); |
| ZLog.Log("World save writing started"); |
| BinaryWriter binary = fileWriter.m_binary; |
| BinaryWriter binary = fileWriter.m_binary; |
| . | binary.Write(33); |
| binary.Write(34); |
| binary.Write(this.m_netTime); |
| binary.Write(this.m_netTime); |
| this.m_zdoMan.SaveAsync(binary); |
| this.m_zdoMan.SaveAsync(binary); |
| ZoneSystem.instance.SaveASync(binary); |
| ZoneSystem.instance.SaveASync(binary); |
| RandEventSystem.instance.SaveAsync(binary); |
| RandEventSystem.instance.SaveAsync(binary); |
| ZLog.Log("World save writing finishing"); |
| ZLog.Log("World save writing finishing"); |
| fileWriter.Finish(); |
| fileWriter.Finish(); |
| SaveSystem.InvalidateCache(); |
| SaveSystem.InvalidateCache(); |
| ZLog.Log("World save writing finished"); |
| ZLog.Log("World save writing finished"); |
| ZNet.m_world.m_needsDB = true; |
| ZNet.m_world.m_needsDB = true; |
| bool flag4; |
| bool flag4; |
| FileWriter fileWriter2; |
| FileWriter fileWriter2; |
| ZNet.m_world.SaveWorldMetaData(now, false, out flag4, out fileWriter2); |
| ZNet.m_world.SaveWorldMetaData(now, false, out flag4, out fileWriter2); |
| if (ZNet.m_world.m_fileSource == FileHelpers.FileSource.Cloud && (fileWriter2.Status == FileWriter.WriterStatus.CloseFailed || fileWriter.Status == FileWriter.WriterStatus.CloseFailed)) |
| if (ZNet.m_world.m_fileSource == FileHelpers.FileSource.Cloud && (fileWriter2.Status == FileWriter.WriterStatus.CloseFailed || fileWriter.Status == FileWriter.WriterStatus.CloseFailed)) |
| { |
| { |
| string text3 = ZNet.<SaveWorldThread>g__GetBackupPath|74_0(ZNet.m_world.GetMetaPath(FileHelpers.FileSource.Local), now); |
| string text3 = ZNet.<SaveWorldThread>g__GetBackupPath|74_0(ZNet.m_world.GetMetaPath(FileHelpers.FileSource.Local), now); |
| string text4 = ZNet.<SaveWorldThread>g__GetBackupPath|74_0(ZNet.m_world.GetDBPath(FileHelpers.FileSource.Local), now); |
| string text4 = ZNet.<SaveWorldThread>g__GetBackupPath|74_0(ZNet.m_world.GetDBPath(FileHelpers.FileSource.Local), now); |
| fileWriter2.DumpCloudWriteToLocalFile(text3); |
| fileWriter2.DumpCloudWriteToLocalFile(text3); |
| fileWriter.DumpCloudWriteToLocalFile(text4); |
| fileWriter.DumpCloudWriteToLocalFile(text4); |
| SaveSystem.InvalidateCache(); |
| SaveSystem.InvalidateCache(); |
| string text5 = ""; |
| string text5 = ""; |
| if (fileWriter2.Status == FileWriter.WriterStatus.CloseFailed) |
| if (fileWriter2.Status == FileWriter.WriterStatus.CloseFailed) |
| { |
| { |
| text5 = text5 + "Cloud save to location \"" + ZNet.m_world.GetMetaPath() + "\" failed!\n"; |
| text5 = text5 + "Cloud save to location \"" + ZNet.m_world.GetMetaPath() + "\" failed!\n"; |
| } |
| } |
| if (fileWriter.Status == FileWriter.WriterStatus.CloseFailed) |
| if (fileWriter.Status == FileWriter.WriterStatus.CloseFailed) |
| { |
| { |
| text5 = text5 + "Cloud save to location \"" + dbpath3 + "\" failed!\n "; |
| text5 = text5 + "Cloud save to location \"" + dbpath3 + "\" failed!\n "; |
| } |
| } |
| text5 = string.Concat(new string[] { text5, "Saved world as local backup \"", text3, "\" and \"", text4, "\". Use the \"Manage saves\" menu to restore this backup." }); |
| text5 = string.Concat(new string[] { text5, "Saved world as local backup \"", text3, "\" and \"", text4, "\". Use the \"Manage saves\" menu to restore this backup." }); |
| ZLog.LogError(text5); |
| ZLog.LogError(text5); |
| } |
| } |
| else |
| else |
| { |
| { |
| if (flag3) |
| if (flag3) |
| { |
| { |
| FileHelpers.ReplaceOldFile(dbpath3, text, text2, ZNet.m_world.m_fileSource); |
| FileHelpers.ReplaceOldFile(dbpath3, text, text2, ZNet.m_world.m_fileSource); |
| SaveSystem.InvalidateCache(); |
| SaveSystem.InvalidateCache(); |
| } |
| } |
| ZLog.Log("World saved ( " + (DateTime.Now - dateTime).TotalMilliseconds.ToString() + "ms )"); |
| ZLog.Log("World saved ( " + (DateTime.Now - dateTime).TotalMilliseconds.ToString() + "ms )"); |
| dateTime = DateTime.Now; |
| dateTime = DateTime.Now; |
| if (ZNet.ConsiderAutoBackup(ZNet.m_world.m_fileName, SaveDataType.World, now)) |
| if (ZNet.ConsiderAutoBackup(ZNet.m_world.m_fileName, SaveDataType.World, now)) |
| { |
| { |
| ZLog.Log("World auto backup saved ( " + (DateTime.Now - dateTime).ToString() + "ms )"); |
| ZLog.Log("World auto backup saved ( " + (DateTime.Now - dateTime).ToString() + "ms )"); |
| } |
| } |
| } |
| } |
| } |
| } |
| catch (Exception ex) |
| catch (Exception ex) |
| { |
| { |
| ZLog.LogError("Error saving world! " + ex.Message); |
| ZLog.LogError("Error saving world! " + ex.Message); |
| Terminal.m_threadSafeMessages.Enqueue("Error saving world! See log or console."); |
| Terminal.m_threadSafeMessages.Enqueue("Error saving world! See log or console."); |
| Terminal.m_threadSafeConsoleLog.Enqueue("Error saving world! " + ex.Message); |
| Terminal.m_threadSafeConsoleLog.Enqueue("Error saving world! " + ex.Message); |
| } |
| } |
| } |
| } |
| |
| |
| public static bool ConsiderAutoBackup(string saveName, SaveDataType dataType, DateTime now) |
| public static bool ConsiderAutoBackup(string saveName, SaveDataType dataType, DateTime now) |
| { |
| { |
| int num = 1200; |
| int num = 1200; |
| int num2 = ((ZNet.m_backupCount == 1) ? 0 : ZNet.m_backupCount); |
| int num2 = ((ZNet.m_backupCount == 1) ? 0 : ZNet.m_backupCount); |
| string text; |
| string text; |
| int num3; |
| int num3; |
| string text2; |
| string text2; |
| int num4; |
| int num4; |
| string text3; |
| string text3; |
| int num5; |
| int num5; |
| return num2 > 0 && SaveSystem.ConsiderBackup(saveName, dataType, now, num2, (Terminal.m_testList.TryGetValue("autoshort", out text) && int.TryParse(text, out num3)) ? num3 : ZNet.m_backupShort, (Terminal.m_testList.TryGetValue("autolong", out text2) && int.TryParse(text2, out num4)) ? num4 : ZNet.m_backupLong, (Terminal.m_testList.TryGetValue("autowait", out text3) && int.TryParse(text3, out num5)) ? num5 : num, ZoneSystem.instance ? ZoneSystem.instance.TimeSinceStart() : 0f); |
| return num2 > 0 && SaveSystem.ConsiderBackup(saveName, dataType, now, num2, (Terminal.m_testList.TryGetValue("autoshort", out text) && int.TryParse(text, out num3)) ? num3 : ZNet.m_backupShort, (Terminal.m_testList.TryGetValue("autolong", out text2) && int.TryParse(text2, out num4)) ? num4 : ZNet.m_backupLong, (Terminal.m_testList.TryGetValue("autowait", out text3) && int.TryParse(text3, out num5)) ? num5 : num, ZoneSystem.instance ? ZoneSystem.instance.TimeSinceStart() : 0f); |
| } |
| } |
| |
| |
| private void LoadWorld() |
| private void LoadWorld() |
| { |
| { |
| ZLog.Log(string.Concat(new string[] |
| ZLog.Log(string.Concat(new string[] |
| { |
| { |
| "Load world: ", |
| "Load world: ", |
| ZNet.m_world.m_name, |
| ZNet.m_world.m_name, |
| " (", |
| " (", |
| ZNet.m_world.m_fileName, |
| ZNet.m_world.m_fileName, |
| ")" |
| ")" |
| })); |
| })); |
| string dbpath = ZNet.m_world.GetDBPath(); |
| string dbpath = ZNet.m_world.GetDBPath(); |
| FileReader fileReader; |
| FileReader fileReader; |
| try |
| try |
| { |
| { |
| fileReader = new FileReader(dbpath, ZNet.m_world.m_fileSource, FileHelpers.FileHelperType.Binary); |
| fileReader = new FileReader(dbpath, ZNet.m_world.m_fileSource, FileHelpers.FileHelperType.Binary); |
| } |
| } |
| catch |
| catch |
| { |
| { |
| ZLog.Log(" missing " + dbpath); |
| ZLog.Log(" missing " + dbpath); |
| this.WorldSetup(); |
| this.WorldSetup(); |
| return; |
| return; |
| } |
| } |
| BinaryReader binary = fileReader.m_binary; |
| BinaryReader binary = fileReader.m_binary; |
| try |
| try |
| { |
| { |
| int num; |
| int num; |
| if (!this.CheckDataVersion(binary, out num)) |
| if (!this.CheckDataVersion(binary, out num)) |
| { |
| { |
| ZLog.Log(" incompatible data version " + num.ToString()); |
| ZLog.Log(" incompatible data version " + num.ToString()); |
| ZNet.m_loadError = true; |
| ZNet.m_loadError = true; |
| binary.Close(); |
| binary.Close(); |
| fileReader.Dispose(); |
| fileReader.Dispose(); |
| this.WorldSetup(); |
| this.WorldSetup(); |
| return; |
| return; |
| } |
| } |
| if (num >= 4) |
| if (num >= 4) |
| { |
| { |
| this.m_netTime = binary.ReadDouble(); |
| this.m_netTime = binary.ReadDouble(); |
| } |
| } |
| this.m_zdoMan.Load(binary, num); |
| this.m_zdoMan.Load(binary, num); |
| if (num >= 12) |
| if (num >= 12) |
| { |
| { |
| ZoneSystem.instance.Load(binary, num); |
| ZoneSystem.instance.Load(binary, num); |
| } |
| } |
| if (num >= 15) |
| if (num >= 15) |
| { |
| { |
| RandEventSystem.instance.Load(binary, num); |
| RandEventSystem.instance.Load(binary, num); |
| } |
| } |
| fileReader.Dispose(); |
| fileReader.Dispose(); |
| this.WorldSetup(); |
| this.WorldSetup(); |
| } |
| } |
| catch (Exception ex) |
| catch (Exception ex) |
| { |
| { |
| ZLog.LogError("Exception while loading world " + dbpath + ":" + ex.ToString()); |
| ZLog.LogError("Exception while loading world " + dbpath + ":" + ex.ToString()); |
| ZNet.m_loadError = true; |
| ZNet.m_loadError = true; |
| } |
| } |
| Game.instance.CollectResources(false); |
| Game.instance.CollectResources(false); |
| } |
| } |
| |
| |
| private bool CheckDataVersion(BinaryReader reader, out int version) |
| private bool CheckDataVersion(BinaryReader reader, out int version) |
| { |
| { |
| version = reader.ReadInt32(); |
| version = reader.ReadInt32(); |
| return global::Version.IsWorldVersionCompatible(version); |
| return global::Version.IsWorldVersionCompatible(version); |
| } |
| } |
| |
| |
| private void WorldSetup() |
| private void WorldSetup() |
| { |
| { |
| ZoneSystem.instance.SetStartingGlobalKeys(true); |
| ZoneSystem.instance.SetStartingGlobalKeys(true); |
| ZNet.m_world.m_startingKeysChanged = false; |
| ZNet.m_world.m_startingKeysChanged = false; |
| } |
| } |
| |
| |
| public int GetHostPort() |
| public int GetHostPort() |
| { |
| { |
| if (this.m_hostSocket != null) |
| if (this.m_hostSocket != null) |
| { |
| { |
| return this.m_hostSocket.GetHostPort(); |
| return this.m_hostSocket.GetHostPort(); |
| } |
| } |
| return 0; |
| return 0; |
| } |
| } |
| |
| |
| public static long GetUID() |
| public static long GetUID() |
| { |
| { |
| return ZDOMan.GetSessionID(); |
| return ZDOMan.GetSessionID(); |
| } |
| } |
| |
| |
| public long GetWorldUID() |
| public long GetWorldUID() |
| { |
| { |
| return ZNet.m_world.m_uid; |
| return ZNet.m_world.m_uid; |
| } |
| } |
| |
| |
| public string GetWorldName() |
| public string GetWorldName() |
| { |
| { |
| if (ZNet.m_world != null) |
| if (ZNet.m_world != null) |
| { |
| { |
| return ZNet.m_world.m_name; |
| return ZNet.m_world.m_name; |
| } |
| } |
| return null; |
| return null; |
| } |
| } |
| |
| |
| public void SetCharacterID(ZDOID id) |
| public void SetCharacterID(ZDOID id) |
| { |
| { |
| this.m_characterID = id; |
| this.m_characterID = id; |
| if (!ZNet.m_isServer) |
| if (!ZNet.m_isServer) |
| { |
| { |
| this.m_peers[0].m_rpc.Invoke("CharacterID", new object[] { id }); |
| this.m_peers[0].m_rpc.Invoke("CharacterID", new object[] { id }); |
| } |
| } |
| } |
| } |
| |
| |
| private void RPC_CharacterID(ZRpc rpc, ZDOID characterID) |
| private void RPC_CharacterID(ZRpc rpc, ZDOID characterID) |
| { |
| { |
| ZNetPeer peer = this.GetPeer(rpc); |
| ZNetPeer peer = this.GetPeer(rpc); |
| if (peer != null) |
| if (peer != null) |
| { |
| { |
| peer.m_characterID = characterID; |
| peer.m_characterID = characterID; |
| string text = "Got character ZDOID from "; |
| string text = "Got character ZDOID from "; |
| string playerName = peer.m_playerName; |
| string playerName = peer.m_playerName; |
| string text2 = " : "; |
| string text2 = " : "; |
| ZDOID zdoid = characterID; |
| ZDOID zdoid = characterID; |
| ZLog.Log(text + playerName + text2 + zdoid.ToString()); |
| ZLog.Log(text + playerName + text2 + zdoid.ToString()); |
| } |
| } |
| } |
| } |
| |
| |
| public void SetPublicReferencePosition(bool pub) |
| public void SetPublicReferencePosition(bool pub) |
| { |
| { |
| this.m_publicReferencePosition = pub; |
| this.m_publicReferencePosition = pub; |
| } |
| } |
| |
| |
| public bool IsReferencePositionPublic() |
| public bool IsReferencePositionPublic() |
| { |
| { |
| return this.m_publicReferencePosition; |
| return this.m_publicReferencePosition; |
| } |
| } |
| |
| |
| public void SetReferencePosition(Vector3 pos) |
| public void SetReferencePosition(Vector3 pos) |
| { |
| { |
| this.m_referencePosition = pos; |
| this.m_referencePosition = pos; |
| } |
| } |
| |
| |
| public Vector3 GetReferencePosition() |
| public Vector3 GetReferencePosition() |
| { |
| { |
| return this.m_referencePosition; |
| return this.m_referencePosition; |
| } |
| } |
| |
| |
| public List<ZDO> GetAllCharacterZDOS() |
| public List<ZDO> GetAllCharacterZDOS() |
| { |
| { |
| List<ZDO> list = new List<ZDO>(); |
| List<ZDO> list = new List<ZDO>(); |
| ZDO zdo = this.m_zdoMan.GetZDO(this.m_characterID); |
| ZDO zdo = this.m_zdoMan.GetZDO(this.m_characterID); |
| if (zdo != null) |
| if (zdo != null) |
| { |
| { |
| list.Add(zdo); |
| list.Add(zdo); |
| } |
| } |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| { |
| { |
| if (znetPeer.IsReady() && !znetPeer.m_characterID.IsNone()) |
| if (znetPeer.IsReady() && !znetPeer.m_characterID.IsNone()) |
| { |
| { |
| ZDO zdo2 = this.m_zdoMan.GetZDO(znetPeer.m_characterID); |
| ZDO zdo2 = this.m_zdoMan.GetZDO(znetPeer.m_characterID); |
| if (zdo2 != null) |
| if (zdo2 != null) |
| { |
| { |
| list.Add(zdo2); |
| list.Add(zdo2); |
| } |
| } |
| } |
| } |
| } |
| } |
| return list; |
| return list; |
| } |
| } |
| |
| |
| public int GetPeerConnections() |
| public int GetPeerConnections() |
| { |
| { |
| int num = 0; |
| int num = 0; |
| for (int i = 0; i < this.m_peers.Count; i++) |
| for (int i = 0; i < this.m_peers.Count; i++) |
| { |
| { |
| if (this.m_peers[i].IsReady()) |
| if (this.m_peers[i].IsReady()) |
| { |
| { |
| num++; |
| num++; |
| } |
| } |
| } |
| } |
| return num; |
| return num; |
| } |
| } |
| |
| |
| public ZNat GetZNat() |
| public ZNat GetZNat() |
| { |
| { |
| return this.m_nat; |
| return this.m_nat; |
| } |
| } |
| |
| |
| public static void SetServer(bool server, bool openServer, bool publicServer, string serverName, string password, World world) |
| public static void SetServer(bool server, bool openServer, bool publicServer, string serverName, string password, World world) |
| { |
| { |
| ZNet.m_isServer = server; |
| ZNet.m_isServer = server; |
| ZNet.m_openServer = openServer; |
| ZNet.m_openServer = openServer; |
| ZNet.m_publicServer = publicServer; |
| ZNet.m_publicServer = publicServer; |
| ZNet.m_serverPassword = (string.IsNullOrEmpty(password) ? "" : ZNet.HashPassword(password, ZNet.ServerPasswordSalt())); |
| ZNet.m_serverPassword = (string.IsNullOrEmpty(password) ? "" : ZNet.HashPassword(password, ZNet.ServerPasswordSalt())); |
| ZNet.m_ServerName = serverName; |
| ZNet.m_ServerName = serverName; |
| ZNet.m_world = world; |
| ZNet.m_world = world; |
| } |
| } |
| |
| |
| private static string HashPassword(string password, string salt) |
| private static string HashPassword(string password, string salt) |
| { |
| { |
| byte[] bytes = Encoding.ASCII.GetBytes(password + salt); |
| byte[] bytes = Encoding.ASCII.GetBytes(password + salt); |
| byte[] array = new MD5CryptoServiceProvider().ComputeHash(bytes); |
| byte[] array = new MD5CryptoServiceProvider().ComputeHash(bytes); |
| return Encoding.ASCII.GetString(array); |
| return Encoding.ASCII.GetString(array); |
| } |
| } |
| |
| |
| public static void ResetServerHost() |
| public static void ResetServerHost() |
| { |
| { |
| ZNet.m_serverPlayFabPlayerId = null; |
| ZNet.m_serverPlayFabPlayerId = null; |
| ZNet.m_serverSteamID = 0UL; |
| ZNet.m_serverSteamID = 0UL; |
| ZNet.m_serverHost = ""; |
| ZNet.m_serverHost = ""; |
| ZNet.m_serverHostPort = 0; |
| ZNet.m_serverHostPort = 0; |
| } |
| } |
| |
| |
| public static bool HasServerHost() |
| public static bool HasServerHost() |
| { |
| { |
| return ZNet.m_serverHost != "" || ZNet.m_serverPlayFabPlayerId != null || ZNet.m_serverSteamID > 0UL; |
| return ZNet.m_serverHost != "" || ZNet.m_serverPlayFabPlayerId != null || ZNet.m_serverSteamID > 0UL; |
| } |
| } |
| |
| |
| public static void SetServerHost(string remotePlayerId) |
| public static void SetServerHost(string remotePlayerId) |
| { |
| { |
| ZNet.ResetServerHost(); |
| ZNet.ResetServerHost(); |
| ZNet.m_serverPlayFabPlayerId = remotePlayerId; |
| ZNet.m_serverPlayFabPlayerId = remotePlayerId; |
| ZNet.m_onlineBackend = OnlineBackendType.PlayFab; |
| ZNet.m_onlineBackend = OnlineBackendType.PlayFab; |
| } |
| } |
| |
| |
| public static void SetServerHost(ulong serverID) |
| public static void SetServerHost(ulong serverID) |
| { |
| { |
| ZNet.ResetServerHost(); |
| ZNet.ResetServerHost(); |
| ZNet.m_serverSteamID = serverID; |
| ZNet.m_serverSteamID = serverID; |
| ZNet.m_onlineBackend = OnlineBackendType.Steamworks; |
| ZNet.m_onlineBackend = OnlineBackendType.Steamworks; |
| } |
| } |
| |
| |
| public static void SetServerHost(string host, int port, OnlineBackendType backend) |
| public static void SetServerHost(string host, int port, OnlineBackendType backend) |
| { |
| { |
| ZNet.ResetServerHost(); |
| ZNet.ResetServerHost(); |
| ZNet.m_serverHost = host; |
| ZNet.m_serverHost = host; |
| ZNet.m_serverHostPort = port; |
| ZNet.m_serverHostPort = port; |
| ZNet.m_onlineBackend = backend; |
| ZNet.m_onlineBackend = backend; |
| } |
| } |
| |
| |
| public static string GetServerString(bool includeBackend = true) |
| public static string GetServerString(bool includeBackend = true) |
| { |
| { |
| if (ZNet.m_onlineBackend == OnlineBackendType.PlayFab) |
| if (ZNet.m_onlineBackend == OnlineBackendType.PlayFab) |
| { |
| { |
| return (includeBackend ? "playfab/" : "") + ZNet.m_serverPlayFabPlayerId; |
| return (includeBackend ? "playfab/" : "") + ZNet.m_serverPlayFabPlayerId; |
| } |
| } |
| if (ZNet.m_onlineBackend == OnlineBackendType.Steamworks) |
| if (ZNet.m_onlineBackend == OnlineBackendType.Steamworks) |
| { |
| { |
| return string.Concat(new string[] |
| return string.Concat(new string[] |
| { |
| { |
| includeBackend ? "steam/" : "", |
| includeBackend ? "steam/" : "", |
| ZNet.m_serverSteamID.ToString(), |
| ZNet.m_serverSteamID.ToString(), |
| "/", |
| "/", |
| ZNet.m_serverHost, |
| ZNet.m_serverHost, |
| ":", |
| ":", |
| ZNet.m_serverHostPort.ToString() |
| ZNet.m_serverHostPort.ToString() |
| }); |
| }); |
| } |
| } |
| return (includeBackend ? "socket/" : "") + ZNet.m_serverHost + ":" + ZNet.m_serverHostPort.ToString(); |
| return (includeBackend ? "socket/" : "") + ZNet.m_serverHost + ":" + ZNet.m_serverHostPort.ToString(); |
| } |
| } |
| |
| |
| public bool IsServer() |
| public bool IsServer() |
| { |
| { |
| return ZNet.m_isServer; |
| return ZNet.m_isServer; |
| } |
| } |
| |
| |
| public static bool IsOpenServer() |
| public static bool IsOpenServer() |
| { |
| { |
| return ZNet.m_openServer; |
| return ZNet.m_openServer; |
| } |
| } |
| |
| |
| public bool IsDedicated() |
| public bool IsDedicated() |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| |
| |
| public static bool IsSinglePlayer |
| public static bool IsSinglePlayer |
| { |
| { |
| get |
| get |
| { |
| { |
| return ZNet.m_isServer && !ZNet.m_openServer; |
| return ZNet.m_isServer && !ZNet.m_openServer; |
| } |
| } |
| } |
| } |
| |
| |
| private void UpdatePlayerList() |
| private void UpdatePlayerList() |
| { |
| { |
| this.m_players.Clear(); |
| this.m_players.Clear(); |
| if (SystemInfo.graphicsDeviceType != GraphicsDeviceType.Null) |
| if (SystemInfo.graphicsDeviceType != GraphicsDeviceType.Null) |
| { |
| { |
| ZNet.PlayerInfo playerInfo = default(ZNet.PlayerInfo); |
| ZNet.PlayerInfo playerInfo = default(ZNet.PlayerInfo); |
| playerInfo.m_name = Game.instance.GetPlayerProfile().GetName(); |
| playerInfo.m_name = Game.instance.GetPlayerProfile().GetName(); |
| playerInfo.m_host = ""; |
| playerInfo.m_host = ""; |
| if (ZNet.m_onlineBackend == OnlineBackendType.PlayFab) |
| if (ZNet.m_onlineBackend == OnlineBackendType.PlayFab) |
| { |
| { |
| playerInfo.m_host = PrivilegeManager.GetNetworkUserId(); |
| playerInfo.m_host = PrivilegeManager.GetNetworkUserId(); |
| } |
| } |
| playerInfo.m_characterID = this.m_characterID; |
| playerInfo.m_characterID = this.m_characterID; |
| playerInfo.m_publicPosition = this.m_publicReferencePosition; |
| playerInfo.m_publicPosition = this.m_publicReferencePosition; |
| if (playerInfo.m_publicPosition) |
| if (playerInfo.m_publicPosition) |
| { |
| { |
| playerInfo.m_position = this.m_referencePosition; |
| playerInfo.m_position = this.m_referencePosition; |
| } |
| } |
| this.m_players.Add(playerInfo); |
| this.m_players.Add(playerInfo); |
| } |
| } |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| { |
| { |
| if (znetPeer.IsReady()) |
| if (znetPeer.IsReady()) |
| { |
| { |
| ZNet.PlayerInfo playerInfo2 = new ZNet.PlayerInfo |
| ZNet.PlayerInfo playerInfo2 = new ZNet.PlayerInfo |
| { |
| { |
| m_characterID = znetPeer.m_characterID, |
| m_characterID = znetPeer.m_characterID, |
| m_name = znetPeer.m_playerName, |
| m_name = znetPeer.m_playerName, |
| m_host = znetPeer.m_socket.GetHostName(), |
| m_host = znetPeer.m_socket.GetHostName(), |
| m_publicPosition = znetPeer.m_publicRefPos |
| m_publicPosition = znetPeer.m_publicRefPos |
| }; |
| }; |
| if (playerInfo2.m_publicPosition) |
| if (playerInfo2.m_publicPosition) |
| { |
| { |
| playerInfo2.m_position = znetPeer.m_refPos; |
| playerInfo2.m_position = znetPeer.m_refPos; |
| } |
| } |
| this.m_players.Add(playerInfo2); |
| this.m_players.Add(playerInfo2); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| private void SendPlayerList() |
| private void SendPlayerList() |
| { |
| { |
| this.UpdatePlayerList(); |
| this.UpdatePlayerList(); |
| if (this.m_peers.Count > 0) |
| if (this.m_peers.Count > 0) |
| { |
| { |
| ZPackage zpackage = new ZPackage(); |
| ZPackage zpackage = new ZPackage(); |
| zpackage.Write(this.m_players.Count); |
| zpackage.Write(this.m_players.Count); |
| foreach (ZNet.PlayerInfo playerInfo in this.m_players) |
| foreach (ZNet.PlayerInfo playerInfo in this.m_players) |
| { |
| { |
| zpackage.Write(playerInfo.m_name); |
| zpackage.Write(playerInfo.m_name); |
| zpackage.Write(playerInfo.m_host); |
| zpackage.Write(playerInfo.m_host); |
| zpackage.Write(playerInfo.m_characterID); |
| zpackage.Write(playerInfo.m_characterID); |
| zpackage.Write(playerInfo.m_publicPosition); |
| zpackage.Write(playerInfo.m_publicPosition); |
| if (playerInfo.m_publicPosition) |
| if (playerInfo.m_publicPosition) |
| { |
| { |
| zpackage.Write(playerInfo.m_position); |
| zpackage.Write(playerInfo.m_position); |
| } |
| } |
| } |
| } |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| { |
| { |
| if (znetPeer.IsReady()) |
| if (znetPeer.IsReady()) |
| { |
| { |
| znetPeer.m_rpc.Invoke("PlayerList", new object[] { zpackage }); |
| znetPeer.m_rpc.Invoke("PlayerList", new object[] { zpackage }); |
| } |
| } |
| } |
| } |
| Action<List<ZNet.PlayerInfo>> playerListUpdated = ZNet.PlayerListUpdated; |
| Action<List<ZNet.PlayerInfo>> playerListUpdated = ZNet.PlayerListUpdated; |
| if (playerListUpdated == null) |
| if (playerListUpdated == null) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| playerListUpdated(this.m_players); |
| playerListUpdated(this.m_players); |
| } |
| } |
| } |
| } |
| |
| |
| private void SendAdminList() |
| private void SendAdminList() |
| { |
| { |
| if (this.m_peers.Count > 0) |
| if (this.m_peers.Count > 0) |
| { |
| { |
| ZPackage zpackage = new ZPackage(); |
| ZPackage zpackage = new ZPackage(); |
| zpackage.Write(this.m_adminList.Count()); |
| zpackage.Write(this.m_adminList.Count()); |
| foreach (string text in this.m_adminList.GetList()) |
| foreach (string text in this.m_adminList.GetList()) |
| { |
| { |
| zpackage.Write(text); |
| zpackage.Write(text); |
| } |
| } |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| { |
| { |
| if (znetPeer.IsReady()) |
| if (znetPeer.IsReady()) |
| { |
| { |
| znetPeer.m_rpc.Invoke("AdminList", new object[] { zpackage }); |
| znetPeer.m_rpc.Invoke("AdminList", new object[] { zpackage }); |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| private void RPC_AdminList(ZRpc rpc, ZPackage pkg) |
| private void RPC_AdminList(ZRpc rpc, ZPackage pkg) |
| { |
| { |
| this.m_adminListForRpc.Clear(); |
| this.m_adminListForRpc.Clear(); |
| int num = pkg.ReadInt(); |
| int num = pkg.ReadInt(); |
| for (int i = 0; i < num; i++) |
| for (int i = 0; i < num; i++) |
| { |
| { |
| string text = pkg.ReadString(); |
| string text = pkg.ReadString(); |
| this.m_adminListForRpc.Add(text); |
| this.m_adminListForRpc.Add(text); |
| } |
| } |
| } |
| } |
| |
| |
| private void RPC_PlayerList(ZRpc rpc, ZPackage pkg) |
| private void RPC_PlayerList(ZRpc rpc, ZPackage pkg) |
| { |
| { |
| this.m_players.Clear(); |
| this.m_players.Clear(); |
| int num = pkg.ReadInt(); |
| int num = pkg.ReadInt(); |
| for (int i = 0; i < num; i++) |
| for (int i = 0; i < num; i++) |
| { |
| { |
| ZNet.PlayerInfo playerInfo = new ZNet.PlayerInfo |
| ZNet.PlayerInfo playerInfo = new ZNet.PlayerInfo |
| { |
| { |
| m_name = pkg.ReadString(), |
| m_name = pkg.ReadString(), |
| m_host = pkg.ReadString(), |
| m_host = pkg.ReadString(), |
| m_characterID = pkg.ReadZDOID(), |
| m_characterID = pkg.ReadZDOID(), |
| m_publicPosition = pkg.ReadBool() |
| m_publicPosition = pkg.ReadBool() |
| }; |
| }; |
| if (playerInfo.m_publicPosition) |
| if (playerInfo.m_publicPosition) |
| { |
| { |
| playerInfo.m_position = pkg.ReadVector3(); |
| playerInfo.m_position = pkg.ReadVector3(); |
| } |
| } |
| this.m_players.Add(playerInfo); |
| this.m_players.Add(playerInfo); |
| } |
| } |
| Action<List<ZNet.PlayerInfo>> playerListUpdated = ZNet.PlayerListUpdated; |
| Action<List<ZNet.PlayerInfo>> playerListUpdated = ZNet.PlayerListUpdated; |
| if (playerListUpdated == null) |
| if (playerListUpdated == null) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| playerListUpdated(this.m_players); |
| playerListUpdated(this.m_players); |
| } |
| } |
| |
| |
| public List<ZNet.PlayerInfo> GetPlayerList() |
| public List<ZNet.PlayerInfo> GetPlayerList() |
| { |
| { |
| return this.m_players; |
| return this.m_players; |
| } |
| } |
| |
| |
| public List<string> GetAdminList() |
| public List<string> GetAdminList() |
| { |
| { |
| return this.m_adminListForRpc; |
| return this.m_adminListForRpc; |
| } |
| } |
| |
| |
| public ZDOID LocalPlayerCharacterID |
| public ZDOID LocalPlayerCharacterID |
| { |
| { |
| get |
| get |
| { |
| { |
| return this.m_characterID; |
| return this.m_characterID; |
| } |
| } |
| } |
| } |
| |
| |
| public void GetOtherPublicPlayers(List<ZNet.PlayerInfo> playerList) |
| public void GetOtherPublicPlayers(List<ZNet.PlayerInfo> playerList) |
| { |
| { |
| foreach (ZNet.PlayerInfo playerInfo in this.m_players) |
| foreach (ZNet.PlayerInfo playerInfo in this.m_players) |
| { |
| { |
| if (playerInfo.m_publicPosition) |
| if (playerInfo.m_publicPosition) |
| { |
| { |
| ZDOID characterID = playerInfo.m_characterID; |
| ZDOID characterID = playerInfo.m_characterID; |
| if (!characterID.IsNone() && !(playerInfo.m_characterID == this.m_characterID)) |
| if (!characterID.IsNone() && !(playerInfo.m_characterID == this.m_characterID)) |
| { |
| { |
| playerList.Add(playerInfo); |
| playerList.Add(playerInfo); |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| public int GetNrOfPlayers() |
| public int GetNrOfPlayers() |
| { |
| { |
| return this.m_players.Count; |
| return this.m_players.Count; |
| } |
| } |
| |
| |
| public void GetNetStats(out float localQuality, out float remoteQuality, out int ping, out float outByteSec, out float inByteSec) |
| public void GetNetStats(out float localQuality, out float remoteQuality, out int ping, out float outByteSec, out float inByteSec) |
| { |
| { |
| localQuality = 0f; |
| localQuality = 0f; |
| remoteQuality = 0f; |
| remoteQuality = 0f; |
| ping = 0; |
| ping = 0; |
| outByteSec = 0f; |
| outByteSec = 0f; |
| inByteSec = 0f; |
| inByteSec = 0f; |
| if (this.IsServer()) |
| if (this.IsServer()) |
| { |
| { |
| int num = 0; |
| int num = 0; |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| { |
| { |
| if (znetPeer.IsReady()) |
| if (znetPeer.IsReady()) |
| { |
| { |
| num++; |
| num++; |
| float num2; |
| float num2; |
| float num3; |
| float num3; |
| int num4; |
| int num4; |
| float num5; |
| float num5; |
| float num6; |
| float num6; |
| znetPeer.m_socket.GetConnectionQuality(out num2, out num3, out num4, out num5, out num6); |
| znetPeer.m_socket.GetConnectionQuality(out num2, out num3, out num4, out num5, out num6); |
| localQuality += num2; |
| localQuality += num2; |
| remoteQuality += num3; |
| remoteQuality += num3; |
| ping += num4; |
| ping += num4; |
| outByteSec += num5; |
| outByteSec += num5; |
| inByteSec += num6; |
| inByteSec += num6; |
| } |
| } |
| } |
| } |
| if (num > 0) |
| if (num > 0) |
| { |
| { |
| localQuality /= (float)num; |
| localQuality /= (float)num; |
| remoteQuality /= (float)num; |
| remoteQuality /= (float)num; |
| ping /= num; |
| ping /= num; |
| } |
| } |
| return; |
| return; |
| } |
| } |
| if (ZNet.m_connectionStatus != ZNet.ConnectionStatus.Connected) |
| if (ZNet.m_connectionStatus != ZNet.ConnectionStatus.Connected) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| foreach (ZNetPeer znetPeer2 in this.m_peers) |
| foreach (ZNetPeer znetPeer2 in this.m_peers) |
| { |
| { |
| if (znetPeer2.IsReady()) |
| if (znetPeer2.IsReady()) |
| { |
| { |
| znetPeer2.m_socket.GetConnectionQuality(out localQuality, out remoteQuality, out ping, out outByteSec, out inByteSec); |
| znetPeer2.m_socket.GetConnectionQuality(out localQuality, out remoteQuality, out ping, out outByteSec, out inByteSec); |
| break; |
| break; |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| public void SetNetTime(double time) |
| public void SetNetTime(double time) |
| { |
| { |
| this.m_netTime = time; |
| this.m_netTime = time; |
| } |
| } |
| |
| |
| public DateTime GetTime() |
| public DateTime GetTime() |
| { |
| { |
| long num = (long)(this.m_netTime * 1000.0 * 10000.0); |
| long num = (long)(this.m_netTime * 1000.0 * 10000.0); |
| return new DateTime(num); |
| return new DateTime(num); |
| } |
| } |
| |
| |
| public float GetWrappedDayTimeSeconds() |
| public float GetWrappedDayTimeSeconds() |
| { |
| { |
| return (float)(this.m_netTime % 86400.0); |
| return (float)(this.m_netTime % 86400.0); |
| } |
| } |
| |
| |
| public double GetTimeSeconds() |
| public double GetTimeSeconds() |
| { |
| { |
| return this.m_netTime; |
| return this.m_netTime; |
| } |
| } |
| |
| |
| public static ZNet.ConnectionStatus GetConnectionStatus() |
| public static ZNet.ConnectionStatus GetConnectionStatus() |
| { |
| { |
| if (ZNet.m_instance != null && ZNet.m_instance.IsServer()) |
| if (ZNet.m_instance != null && ZNet.m_instance.IsServer()) |
| { |
| { |
| return ZNet.ConnectionStatus.Connected; |
| return ZNet.ConnectionStatus.Connected; |
| } |
| } |
| if (ZNet.m_externalError != ZNet.ConnectionStatus.None) |
| if (ZNet.m_externalError != ZNet.ConnectionStatus.None) |
| { |
| { |
| ZNet.m_connectionStatus = ZNet.m_externalError; |
| ZNet.m_connectionStatus = ZNet.m_externalError; |
| } |
| } |
| return ZNet.m_connectionStatus; |
| return ZNet.m_connectionStatus; |
| } |
| } |
| |
| |
| public bool HasBadConnection() |
| public bool HasBadConnection() |
| { |
| { |
| return this.GetServerPing() > this.m_badConnectionPing; |
| return this.GetServerPing() > this.m_badConnectionPing; |
| } |
| } |
| |
| |
| public float GetServerPing() |
| public float GetServerPing() |
| { |
| { |
| if (this.IsServer()) |
| if (this.IsServer()) |
| { |
| { |
| return 0f; |
| return 0f; |
| } |
| } |
| if (ZNet.m_connectionStatus == ZNet.ConnectionStatus.Connecting || ZNet.m_connectionStatus == ZNet.ConnectionStatus.None) |
| if (ZNet.m_connectionStatus == ZNet.ConnectionStatus.Connecting || ZNet.m_connectionStatus == ZNet.ConnectionStatus.None) |
| { |
| { |
| return 0f; |
| return 0f; |
| } |
| } |
| if (ZNet.m_connectionStatus == ZNet.ConnectionStatus.Connected) |
| if (ZNet.m_connectionStatus == ZNet.ConnectionStatus.Connected) |
| { |
| { |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| { |
| { |
| if (znetPeer.IsReady()) |
| if (znetPeer.IsReady()) |
| { |
| { |
| return znetPeer.m_rpc.GetTimeSinceLastPing(); |
| return znetPeer.m_rpc.GetTimeSinceLastPing(); |
| } |
| } |
| } |
| } |
| } |
| } |
| return 0f; |
| return 0f; |
| } |
| } |
| |
| |
| public ZNetPeer GetServerPeer() |
| public ZNetPeer GetServerPeer() |
| { |
| { |
| if (this.IsServer()) |
| if (this.IsServer()) |
| { |
| { |
| return null; |
| return null; |
| } |
| } |
| if (ZNet.m_connectionStatus == ZNet.ConnectionStatus.Connecting || ZNet.m_connectionStatus == ZNet.ConnectionStatus.None) |
| if (ZNet.m_connectionStatus == ZNet.ConnectionStatus.Connecting || ZNet.m_connectionStatus == ZNet.ConnectionStatus.None) |
| { |
| { |
| return null; |
| return null; |
| } |
| } |
| if (ZNet.m_connectionStatus == ZNet.ConnectionStatus.Connected) |
| if (ZNet.m_connectionStatus == ZNet.ConnectionStatus.Connected) |
| { |
| { |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| foreach (ZNetPeer znetPeer in this.m_peers) |
| { |
| { |
| if (znetPeer.IsReady()) |
| if (znetPeer.IsReady()) |
| { |
| { |
| return znetPeer; |
| return znetPeer; |
| } |
| } |
| } |
| } |
| } |
| } |
| return null; |
| return null; |
| } |
| } |
| |
| |
| public ZRpc GetServerRPC() |
| public ZRpc GetServerRPC() |
| { |
| { |
| ZNetPeer serverPeer = this.GetServerPeer(); |
| ZNetPeer serverPeer = this.GetServerPeer(); |
| if (serverPeer != null) |
| if (serverPeer != null) |
| { |
| { |
| return serverPeer.m_rpc; |
| return serverPeer.m_rpc; |
| } |
| } |
| return null; |
| return null; |
| } |
| } |
| |
| |
| public List<ZNetPeer> GetPeers() |
| public List<ZNetPeer> GetPeers() |
| { |
| { |
| return this.m_peers; |
| return this.m_peers; |
| } |
| } |
| |
| |
| public void RemotePrint(ZRpc rpc, string text) |
| public void RemotePrint(ZRpc rpc, string text) |
| { |
| { |
| if (rpc == null) |
| if (rpc == null) |
| { |
| { |
| if (global::Console.instance) |
| if (global::Console.instance) |
| { |
| { |
| global::Console.instance.Print(text); |
| global::Console.instance.Print(text); |
| return; |
| return; |
| } |
| } |
| } |
| } |
| else |
| else |
| { |
| { |
| rpc.Invoke("RemotePrint", new object[] { text }); |
| rpc.Invoke("RemotePrint", new object[] { text }); |
| } |
| } |
| } |
| } |
| |
| |
| private void RPC_RemotePrint(ZRpc rpc, string text) |
| private void RPC_RemotePrint(ZRpc rpc, string text) |
| { |
| { |
| if (global::Console.instance) |
| if (global::Console.instance) |
| { |
| { |
| global::Console.instance.Print(text); |
| global::Console.instance.Print(text); |
| } |
| } |
| } |
| } |
| |
| |
| public void Kick(string user) |
| public void Kick(string user) |
| { |
| { |
| if (this.IsServer()) |
| if (this.IsServer()) |
| { |
| { |
| this.InternalKick(user); |
| this.InternalKick(user); |
| return; |
| return; |
| } |
| } |
| ZRpc serverRPC = this.GetServerRPC(); |
| ZRpc serverRPC = this.GetServerRPC(); |
| if (serverRPC != null) |
| if (serverRPC != null) |
| { |
| { |
| serverRPC.Invoke("Kick", new object[] { user }); |
| serverRPC.Invoke("Kick", new object[] { user }); |
| } |
| } |
| } |
| } |
| |
| |
| private void RPC_Kick(ZRpc rpc, string user) |
| private void RPC_Kick(ZRpc rpc, string user) |
| { |
| { |
| if (!this.ListContainsId(this.m_adminList, rpc.GetSocket().GetHostName())) |
| if (!this.ListContainsId(this.m_adminList, rpc.GetSocket().GetHostName())) |
| { |
| { |
| this.RemotePrint(rpc, "You are not admin"); |
| this.RemotePrint(rpc, "You are not admin"); |
| return; |
| return; |
| } |
| } |
| this.RemotePrint(rpc, "Kicking user " + user); |
| this.RemotePrint(rpc, "Kicking user " + user); |
| this.InternalKick(user); |
| this.InternalKick(user); |
| } |
| } |
| |
| |
| private void RPC_Kicked(ZRpc rpc) |
| private void RPC_Kicked(ZRpc rpc) |
| { |
| { |
| ZNetPeer peer = this.GetPeer(rpc); |
| ZNetPeer peer = this.GetPeer(rpc); |
| if (peer == null || !peer.m_server) |
| if (peer == null || !peer.m_server) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| ZNet.m_connectionStatus = ZNet.ConnectionStatus.ErrorKicked; |
| ZNet.m_connectionStatus = ZNet.ConnectionStatus.ErrorKicked; |
| this.Disconnect(peer); |
| this.Disconnect(peer); |
| } |
| } |
| |
| |
| private void InternalKick(string user) |
| private void InternalKick(string user) |
| { |
| { |
| if (user == "") |
| if (user == "") |
| { |
| { |
| return; |
| return; |
| } |
| } |
| ZNetPeer znetPeer = null; |
| ZNetPeer znetPeer = null; |
| if (ZNet.m_onlineBackend == OnlineBackendType.Steamworks) |
| if (ZNet.m_onlineBackend == OnlineBackendType.Steamworks) |
| { |
| { |
| if (user.StartsWith(PrivilegeManager.GetPlatformPrefix(PrivilegeManager.Platform.Steam))) |
| if (user.StartsWith(PrivilegeManager.GetPlatformPrefix(PrivilegeManager.Platform.Steam))) |
| { |
| { |
| znetPeer = this.GetPeerByHostName(user.Substring(PrivilegeManager.GetPlatformPrefix(PrivilegeManager.Platform.Steam).Length)); |
| znetPeer = this.GetPeerByHostName(user.Substring(PrivilegeManager.GetPlatformPrefix(PrivilegeManager.Platform.Steam).Length)); |
| } |
| } |
| else if (!user.Contains("_")) |
| else if (!user.Contains("_")) |
| { |
| { |
| znetPeer = this.GetPeerByHostName(user); |
| znetPeer = this.GetPeerByHostName(user); |
| } |
| } |
| } |
| } |
| else if (!user.Contains("_")) |
| else if (!user.Contains("_")) |
| { |
| { |
| znetPeer = this.GetPeerByHostName(PrivilegeManager.GetPlatformPrefix(PrivilegeManager.Platform.Steam) + user); |
| znetPeer = this.GetPeerByHostName(PrivilegeManager.GetPlatformPrefix(PrivilegeManager.Platform.Steam) + user); |
| } |
| } |
| else |
| else |
| { |
| { |
| znetPeer = this.GetPeerByHostName(user); |
| znetPeer = this.GetPeerByHostName(user); |
| } |
| } |
| if (znetPeer == null) |
| if (znetPeer == null) |
| { |
| { |
| znetPeer = this.GetPeerByPlayerName(user); |
| znetPeer = this.GetPeerByPlayerName(user); |
| } |
| } |
| if (znetPeer != null) |
| if (znetPeer != null) |
| { |
| { |
| this.InternalKick(znetPeer); |
| this.InternalKick(znetPeer); |
| } |
| } |
| } |
| } |
| |
| |
| private void InternalKick(ZNetPeer peer) |
| private void InternalKick(ZNetPeer peer) |
| { |
| { |
| if (!this.IsServer() || peer == null || ZNet.PeersToDisconnectAfterKick.ContainsKey(peer)) |
| if (!this.IsServer() || peer == null || ZNet.PeersToDisconnectAfterKick.ContainsKey(peer)) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| ZLog.Log("Kicking " + peer.m_playerName); |
| ZLog.Log("Kicking " + peer.m_playerName); |
| peer.m_rpc.Invoke("Kicked", Array.Empty<object>()); |
| peer.m_rpc.Invoke("Kicked", Array.Empty<object>()); |
| ZNet.PeersToDisconnectAfterKick[peer] = Time.time + 1f; |
| ZNet.PeersToDisconnectAfterKick[peer] = Time.time + 1f; |
| } |
| } |
| |
| |
| private bool IsAllowed(string hostName, string playerName) |
| private bool IsAllowed(string hostName, string playerName) |
| { |
| { |
| return !this.ListContainsId(this.m_bannedList, hostName) && !this.m_bannedList.Contains(playerName) && (this.m_permittedList.Count() <= 0 || this.ListContainsId(this.m_permittedList, hostName)); |
| return !this.ListContainsId(this.m_bannedList, hostName) && !this.m_bannedList.Contains(playerName) && (this.m_permittedList.Count() <= 0 || this.ListContainsId(this.m_permittedList, hostName)); |
| } |
| } |
| |
| |
| public void Ban(string user) |
| public void Ban(string user) |
| { |
| { |
| if (this.IsServer()) |
| if (this.IsServer()) |
| { |
| { |
| this.InternalBan(null, user); |
| this.InternalBan(null, user); |
| return; |
| return; |
| } |
| } |
| ZRpc serverRPC = this.GetServerRPC(); |
| ZRpc serverRPC = this.GetServerRPC(); |
| if (serverRPC != null) |
| if (serverRPC != null) |
| { |
| { |
| serverRPC.Invoke("Ban", new object[] { user }); |
| serverRPC.Invoke("Ban", new object[] { user }); |
| } |
| } |
| } |
| } |
| |
| |
| private void RPC_Ban(ZRpc rpc, string user) |
| private void RPC_Ban(ZRpc rpc, string user) |
| { |
| { |
| if (!this.ListContainsId(this.m_adminList, rpc.GetSocket().GetHostName())) |
| if (!this.ListContainsId(this.m_adminList, rpc.GetSocket().GetHostName())) |
| { |
| { |
| this.RemotePrint(rpc, "You are not admin"); |
| this.RemotePrint(rpc, "You are not admin"); |
| return; |
| return; |
| } |
| } |
| this.InternalBan(rpc, user); |
| this.InternalBan(rpc, user); |
| } |
| } |
| |
| |
| private void InternalBan(ZRpc rpc, string user) |
| private void InternalBan(ZRpc rpc, string user) |
| { |
| { |
| if (!this.IsServer()) |
| if (!this.IsServer()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (user == "") |
| if (user == "") |
| { |
| { |
| return; |
| return; |
| } |
| } |
| ZNetPeer peerByPlayerName = this.GetPeerByPlayerName(user); |
| ZNetPeer peerByPlayerName = this.GetPeerByPlayerName(user); |
| if (peerByPlayerName != null) |
| if (peerByPlayerName != null) |
| { |
| { |
| user = peerByPlayerName.m_socket.GetHostName(); |
| user = peerByPlayerName.m_socket.GetHostName(); |
| } |
| } |
| this.RemotePrint(rpc, "Banning user " + user); |
| this.RemotePrint(rpc, "Banning user " + user); |
| this.m_bannedList.Add(user); |
| this.m_bannedList.Add(user); |
| } |
| } |
| |
| |
| public void Unban(string user) |
| public void Unban(string user) |
| { |
| { |
| if (this.IsServer()) |
| if (this.IsServer()) |
| { |
| { |
| this.InternalUnban(null, user); |
| this.InternalUnban(null, user); |
| return; |
| return; |
| } |
| } |
| ZRpc serverRPC = this.GetServerRPC(); |
| ZRpc serverRPC = this.GetServerRPC(); |
| if (serverRPC != null) |
| if (serverRPC != null) |
| { |
| { |
| serverRPC.Invoke("Unban", new object[] { user }); |
| serverRPC.Invoke("Unban", new object[] { user }); |
| } |
| } |
| } |
| } |
| |
| |
| private void RPC_Unban(ZRpc rpc, string user) |
| private void RPC_Unban(ZRpc rpc, string user) |
| { |
| { |
| if (!this.ListContainsId(this.m_adminList, rpc.GetSocket().GetHostName())) |
| if (!this.ListContainsId(this.m_adminList, rpc.GetSocket().GetHostName())) |
| { |
| { |
| this.RemotePrint(rpc, "You are not admin"); |
| this.RemotePrint(rpc, "You are not admin"); |
| return; |
| return; |
| } |
| } |
| this.InternalUnban(rpc, user); |
| this.InternalUnban(rpc, user); |
| } |
| } |
| |
| |
| private void InternalUnban(ZRpc rpc, string user) |
| private void InternalUnban(ZRpc rpc, string user) |
| { |
| { |
| if (!this.IsServer()) |
| if (!this.IsServer()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (user == "") |
| if (user == "") |
| { |
| { |
| return; |
| return; |
| } |
| } |
| this.RemotePrint(rpc, "Unbanning user " + user); |
| this.RemotePrint(rpc, "Unbanning user " + user); |
| this.m_bannedList.Remove(user); |
| this.m_bannedList.Remove(user); |
| } |
| } |
| |
| |
| public bool IsAdmin(string hostName) |
| public bool IsAdmin(string hostName) |
| { |
| { |
| return this.ListContainsId(this.m_adminList, hostName); |
| return this.ListContainsId(this.m_adminList, hostName); |
| } |
| } |
| |
| |
| public List<string> Banned |
| public List<string> Banned |
| { |
| { |
| get |
| get |
| { |
| { |
| return this.m_bannedList.GetList(); |
| return this.m_bannedList.GetList(); |
| } |
| } |
| } |
| } |
| |
| |
| public void PrintBanned() |
| public void PrintBanned() |
| { |
| { |
| if (this.IsServer()) |
| if (this.IsServer()) |
| { |
| { |
| this.InternalPrintBanned(null); |
| this.InternalPrintBanned(null); |
| return; |
| return; |
| } |
| } |
| ZRpc serverRPC = this.GetServerRPC(); |
| ZRpc serverRPC = this.GetServerRPC(); |
| if (serverRPC != null) |
| if (serverRPC != null) |
| { |
| { |
| serverRPC.Invoke("PrintBanned", Array.Empty<object>()); |
| serverRPC.Invoke("PrintBanned", Array.Empty<object>()); |
| } |
| } |
| } |
| } |
| |
| |
| private void RPC_PrintBanned(ZRpc rpc) |
| private void RPC_PrintBanned(ZRpc rpc) |
| { |
| { |
| if (!this.ListContainsId(this.m_adminList, rpc.GetSocket().GetHostName())) |
| if (!this.ListContainsId(this.m_adminList, rpc.GetSocket().GetHostName())) |
| { |
| { |
| this.RemotePrint(rpc, "You are not admin"); |
| this.RemotePrint(rpc, "You are not admin"); |
| return; |
| return; |
| } |
| } |
| this.InternalPrintBanned(rpc); |
| this.InternalPrintBanned(rpc); |
| } |
| } |
| |
| |
| private void InternalPrintBanned(ZRpc rpc) |
| private void InternalPrintBanned(ZRpc rpc) |
| { |
| { |
| this.RemotePrint(rpc, "Banned users"); |
| this.RemotePrint(rpc, "Banned users"); |
| List<string> list = this.m_bannedList.GetList(); |
| List<string> list = this.m_bannedList.GetList(); |
| if (list.Count == 0) |
| if (list.Count == 0) |
| { |
| { |
| this.RemotePrint(rpc, "-"); |
| this.RemotePrint(rpc, "-"); |
| } |
| } |
| else |
| else |
| { |
| { |
| for (int i = 0; i < list.Count; i++) |
| for (int i = 0; i < list.Count; i++) |
| { |
| { |
| this.RemotePrint(rpc, i.ToString() + ": " + list[i]); |
| this.RemotePrint(rpc, i.ToString() + ": " + list[i]); |
| } |
| } |
| } |
| } |
| this.RemotePrint(rpc, ""); |
| this.RemotePrint(rpc, ""); |
| this.RemotePrint(rpc, "Permitted users"); |
| this.RemotePrint(rpc, "Permitted users"); |
| List<string> list2 = this.m_permittedList.GetList(); |
| List<string> list2 = this.m_permittedList.GetList(); |
| if (list2.Count == 0) |
| if (list2.Count == 0) |
| { |
| { |
| this.RemotePrint(rpc, "All"); |
| this.RemotePrint(rpc, "All"); |
| return; |
| return; |
| } |
| } |
| for (int j = 0; j < list2.Count; j++) |
| for (int j = 0; j < list2.Count; j++) |
| { |
| { |
| this.RemotePrint(rpc, j.ToString() + ": " + list2[j]); |
| this.RemotePrint(rpc, j.ToString() + ": " + list2[j]); |
| } |
| } |
| } |
| } |
| |
| |
| public void RemoteCommand(string command) |
| public void RemoteCommand(string command) |
| { |
| { |
| if (this.IsServer()) |
| if (this.IsServer()) |
| { |
| { |
| this.InternalCommand(null, command); |
| this.InternalCommand(null, command); |
| return; |
| return; |
| } |
| } |
| ZRpc serverRPC = this.GetServerRPC(); |
| ZRpc serverRPC = this.GetServerRPC(); |
| if (serverRPC != null) |
| if (serverRPC != null) |
| { |
| { |
| serverRPC.Invoke("RPC_RemoteCommand", new object[] { command }); |
| serverRPC.Invoke("RPC_RemoteCommand", new object[] { command }); |
| } |
| } |
| } |
| } |
| |
| |
| private void RPC_RemoteCommand(ZRpc rpc, string command) |
| private void RPC_RemoteCommand(ZRpc rpc, string command) |
| { |
| { |
| if (!this.ListContainsId(this.m_adminList, rpc.GetSocket().GetHostName())) |
| if (!this.ListContainsId(this.m_adminList, rpc.GetSocket().GetHostName())) |
| { |
| { |
| this.RemotePrint(rpc, "You are not admin"); |
| this.RemotePrint(rpc, "You are not admin"); |
| return; |
| return; |
| } |
| } |
| this.InternalCommand(rpc, command); |
| this.InternalCommand(rpc, command); |
| } |
| } |
| |
| |
| private void InternalCommand(ZRpc rpc, string command) |
| private void InternalCommand(ZRpc rpc, string command) |
| { |
| { |
| ZLog.Log(string.Concat(new string[] |
| ZLog.Log(string.Concat(new string[] |
| { |
| { |
| "Remote admin '", |
| "Remote admin '", |
| rpc.GetSocket().GetHostName(), |
| rpc.GetSocket().GetHostName(), |
| "' executed command '", |
| "' executed command '", |
| command, |
| command, |
| "' remotely." |
| "' remotely." |
| })); |
| })); |
| global::Console.instance.TryRunCommand(command, false, false); |
| global::Console.instance.TryRunCommand(command, false, false); |
| } |
| } |
| |
| |
| private static string ServerPasswordSalt() |
| private static string ServerPasswordSalt() |
| { |
| { |
| if (ZNet.m_serverPasswordSalt.Length == 0) |
| if (ZNet.m_serverPasswordSalt.Length == 0) |
| { |
| { |
| byte[] array = new byte[16]; |
| byte[] array = new byte[16]; |
| RandomNumberGenerator.Create().GetBytes(array); |
| RandomNumberGenerator.Create().GetBytes(array); |
| ZNet.m_serverPasswordSalt = Encoding.ASCII.GetString(array); |
| ZNet.m_serverPasswordSalt = Encoding.ASCII.GetString(array); |
| } |
| } |
| return ZNet.m_serverPasswordSalt; |
| return ZNet.m_serverPasswordSalt; |
| } |
| } |
| |
| |
| public static void SetExternalError(ZNet.ConnectionStatus error) |
| public static void SetExternalError(ZNet.ConnectionStatus error) |
| { |
| { |
| ZNet.m_externalError = error; |
| ZNet.m_externalError = error; |
| } |
| } |
| |
| |
| public bool HaveStopped |
| public bool HaveStopped |
| { |
| { |
| get |
| get |
| { |
| { |
| return this.m_haveStoped; |
| return this.m_haveStoped; |
| } |
| } |
| } |
| } |
| |
| |
| public static World World |
| public static World World |
| { |
| { |
| get |
| get |
| { |
| { |
| return ZNet.m_world; |
| return ZNet.m_world; |
| } |
| } |
| } |
| } |
| |
| |
| public static event Action<List<ZNet.PlayerInfo>> PlayerListUpdated; |
| public static event Action<List<ZNet.PlayerInfo>> PlayerListUpdated; |
| |
| |
| [CompilerGenerated] |
| [CompilerGenerated] |
| internal static string <GetPublicIP>g__DownloadString|10_0(string downloadUrl, int timeoutMS = 5000) |
| internal static string <GetPublicIP>g__DownloadString|10_0(string downloadUrl, int timeoutMS = 5000) |
| { |
| { |
| HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(downloadUrl); |
| HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(downloadUrl); |
| httpWebRequest.Timeout = timeoutMS; |
| httpWebRequest.Timeout = timeoutMS; |
| httpWebRequest.ReadWriteTimeout = timeoutMS; |
| httpWebRequest.ReadWriteTimeout = timeoutMS; |
| string text; |
| string text; |
| try |
| try |
| { |
| { |
| text = new StreamReader(((HttpWebResponse)httpWebRequest.GetResponse()).GetResponseStream()).ReadToEnd(); |
| text = new StreamReader(((HttpWebResponse)httpWebRequest.GetResponse()).GetResponseStream()).ReadToEnd(); |
| } |
| } |
| catch (Exception ex) |
| catch (Exception ex) |
| { |
| { |
| ZLog.Log("Exception while waiting for respons from " + downloadUrl + " -> " + ex.ToString()); |
| ZLog.Log("Exception while waiting for respons from " + downloadUrl + " -> " + ex.ToString()); |
| text = ""; |
| text = ""; |
| } |
| } |
| return text; |
| return text; |
| } |
| } |
| |
| |
| [CompilerGenerated] |
| [CompilerGenerated] |
| private void <OnSteamServerRegistered>g__RetryRegisterAfterDelay|11_0(float delay) |
| private void <OnSteamServerRegistered>g__RetryRegisterAfterDelay|11_0(float delay) |
| { |
| { |
| base.StartCoroutine(this.<OnSteamServerRegistered>g__DelayThenRegisterCoroutine|11_1(delay)); |
| base.StartCoroutine(this.<OnSteamServerRegistered>g__DelayThenRegisterCoroutine|11_1(delay)); |
| } |
| } |
| |
| |
| [CompilerGenerated] |
| [CompilerGenerated] |
| private IEnumerator <OnSteamServerRegistered>g__DelayThenRegisterCoroutine|11_1(float delay) |
| private IEnumerator <OnSteamServerRegistered>g__DelayThenRegisterCoroutine|11_1(float delay) |
| { |
| { |
| ZLog.Log(string.Format("Steam register server failed! Retrying in {0}s, total attempts: {1}", delay, this.m_registerAttempts)); |
| ZLog.Log(string.Format("Steam register server failed! Retrying in {0}s, total attempts: {1}", delay, this.m_registerAttempts)); |
| DateTime NextRetryUtc = DateTime.UtcNow + TimeSpan.FromSeconds((double)delay); |
| DateTime NextRetryUtc = DateTime.UtcNow + TimeSpan.FromSeconds((double)delay); |
| while (DateTime.UtcNow < NextRetryUtc) |
| while (DateTime.UtcNow < NextRetryUtc) |
| { |
| { |
| yield return null; |
| yield return null; |
| } |
| } |
| bool flag = ZNet.m_serverPassword != ""; |
| bool flag = ZNet.m_serverPassword != ""; |
| GameVersion currentVersion = global::Version.CurrentVersion; |
| GameVersion currentVersion = global::Version.CurrentVersion; |
| . | uint num = 23U; |
| uint num = 27U; |
| List<string> startingGlobalKeys = ZNet.m_world.m_startingGlobalKeys; |
| List<string> startingGlobalKeys = ZNet.m_world.m_startingGlobalKeys; |
| ZSteamMatchmaking.instance.RegisterServer(ZNet.m_ServerName, flag, currentVersion, startingGlobalKeys, num, ZNet.m_publicServer, ZNet.m_world.m_seedName, new ZSteamMatchmaking.ServerRegistered(this.OnSteamServerRegistered)); |
| ZSteamMatchmaking.instance.RegisterServer(ZNet.m_ServerName, flag, currentVersion, startingGlobalKeys, num, ZNet.m_publicServer, ZNet.m_world.m_seedName, new ZSteamMatchmaking.ServerRegistered(this.OnSteamServerRegistered)); |
| yield break; |
| yield break; |
| } |
| } |
| |
| |
| [CompilerGenerated] |
| [CompilerGenerated] |
| internal static string <SaveWorldThread>g__GetBackupPath|74_0(string filePath, DateTime now) |
| internal static string <SaveWorldThread>g__GetBackupPath|74_0(string filePath, DateTime now) |
| { |
| { |
| string text; |
| string text; |
| string text2; |
| string text2; |
| string text3; |
| string text3; |
| FileHelpers.SplitFilePath(filePath, out text, out text2, out text3); |
| FileHelpers.SplitFilePath(filePath, out text, out text2, out text3); |
| return string.Concat(new string[] |
| return string.Concat(new string[] |
| { |
| { |
| text, |
| text, |
| text2, |
| text2, |
| "_backup_cloud-", |
| "_backup_cloud-", |
| now.ToString("yyyyMMdd-HHmmss"), |
| now.ToString("yyyyMMdd-HHmmss"), |
| text3 |
| text3 |
| }); |
| }); |
| } |
| } |
| |
| |
| public static Action WorldSaveStarted; |
| public static Action WorldSaveStarted; |
| |
| |
| public static Action WorldSaveFinished; |
| public static Action WorldSaveFinished; |
| |
| |
| private float m_banlistTimer; |
| private float m_banlistTimer; |
| |
| |
| private static ZNet m_instance; |
| private static ZNet m_instance; |
| |
| |
| public const int ServerPlayerLimit = 10; |
| public const int ServerPlayerLimit = 10; |
| |
| |
| public int m_hostPort = 2456; |
| public int m_hostPort = 2456; |
| |
| |
| public RectTransform m_passwordDialog; |
| public RectTransform m_passwordDialog; |
| |
| |
| public RectTransform m_connectingDialog; |
| public RectTransform m_connectingDialog; |
| |
| |
| public float m_badConnectionPing = 5f; |
| public float m_badConnectionPing = 5f; |
| |
| |
| public int m_zdoSectorsWidth = 512; |
| public int m_zdoSectorsWidth = 512; |
| |
| |
| private ZConnector2 m_serverConnector; |
| private ZConnector2 m_serverConnector; |
| |
| |
| private ISocket m_hostSocket; |
| private ISocket m_hostSocket; |
| |
| |
| private List<ZNetPeer> m_peers = new List<ZNetPeer>(); |
| private List<ZNetPeer> m_peers = new List<ZNetPeer>(); |
| |
| |
| private Thread m_saveThread; |
| private Thread m_saveThread; |
| |
| |
| private bool m_saveExceededCloudQuota; |
| private bool m_saveExceededCloudQuota; |
| |
| |
| private float m_saveStartTime; |
| private float m_saveStartTime; |
| |
| |
| private float m_saveThreadStartTime; |
| private float m_saveThreadStartTime; |
| |
| |
| public static bool m_loadError = false; |
| public static bool m_loadError = false; |
| |
| |
| private float m_sendSaveMessage; |
| private float m_sendSaveMessage; |
| |
| |
| private ZDOMan m_zdoMan; |
| private ZDOMan m_zdoMan; |
| |
| |
| private ZRoutedRpc m_routedRpc; |
| private ZRoutedRpc m_routedRpc; |
| |
| |
| private ZNat m_nat; |
| private ZNat m_nat; |
| |
| |
| private double m_netTime = 2040.0; |
| private double m_netTime = 2040.0; |
| |
| |
| private ZDOID m_characterID = ZDOID.None; |
| private ZDOID m_characterID = ZDOID.None; |
| |
| |
| private Vector3 m_referencePosition = Vector3.zero; |
| private Vector3 m_referencePosition = Vector3.zero; |
| |
| |
| private bool m_publicReferencePosition; |
| private bool m_publicReferencePosition; |
| |
| |
| private float m_periodicSendTimer; |
| private float m_periodicSendTimer; |
| |
| |
| public Dictionary<string, string> m_serverSyncedPlayerData = new Dictionary<string, string>(); |
| public Dictionary<string, string> m_serverSyncedPlayerData = new Dictionary<string, string>(); |
| |
| |
| public static int m_backupCount = 2; |
| public static int m_backupCount = 2; |
| |
| |
| public static int m_backupShort = 7200; |
| public static int m_backupShort = 7200; |
| |
| |
| public static int m_backupLong = 43200; |
| public static int m_backupLong = 43200; |
| |
| |
| private bool m_haveStoped; |
| private bool m_haveStoped; |
| |
| |
| private static bool m_isServer = true; |
| private static bool m_isServer = true; |
| |
| |
| private static World m_world = null; |
| private static World m_world = null; |
| |
| |
| private int m_registerAttempts; |
| private int m_registerAttempts; |
| |
| |
| public static OnlineBackendType m_onlineBackend = OnlineBackendType.Steamworks; |
| public static OnlineBackendType m_onlineBackend = OnlineBackendType.Steamworks; |
| |
| |
| private static string m_serverPlayFabPlayerId = null; |
| private static string m_serverPlayFabPlayerId = null; |
| |
| |
| private static ulong m_serverSteamID = 0UL; |
| private static ulong m_serverSteamID = 0UL; |
| |
| |
| private static string m_serverHost = ""; |
| private static string m_serverHost = ""; |
| |
| |
| private static int m_serverHostPort = 0; |
| private static int m_serverHostPort = 0; |
| |
| |
| private static bool m_openServer = true; |
| private static bool m_openServer = true; |
| |
| |
| private static bool m_publicServer = true; |
| private static bool m_publicServer = true; |
| |
| |
| private static string m_serverPassword = ""; |
| private static string m_serverPassword = ""; |
| |
| |
| private static string m_serverPasswordSalt = ""; |
| private static string m_serverPasswordSalt = ""; |
| |
| |
| private static string m_ServerName = ""; |
| private static string m_ServerName = ""; |
| |
| |
| private static ZNet.ConnectionStatus m_connectionStatus = ZNet.ConnectionStatus.None; |
| private static ZNet.ConnectionStatus m_connectionStatus = ZNet.ConnectionStatus.None; |
| |
| |
| private static ZNet.ConnectionStatus m_externalError = ZNet.ConnectionStatus.None; |
| private static ZNet.ConnectionStatus m_externalError = ZNet.ConnectionStatus.None; |
| |
| |
| private SyncedList m_adminList; |
| private SyncedList m_adminList; |
| |
| |
| private SyncedList m_bannedList; |
| private SyncedList m_bannedList; |
| |
| |
| private SyncedList m_permittedList; |
| private SyncedList m_permittedList; |
| |
| |
| private List<ZNet.PlayerInfo> m_players = new List<ZNet.PlayerInfo>(); |
| private List<ZNet.PlayerInfo> m_players = new List<ZNet.PlayerInfo>(); |
| |
| |
| private List<string> m_adminListForRpc = new List<string>(); |
| private List<string> m_adminListForRpc = new List<string>(); |
| |
| |
| private ZRpc m_tempPasswordRPC; |
| private ZRpc m_tempPasswordRPC; |
| |
| |
| private static readonly Dictionary<ZNetPeer, float> PeersToDisconnectAfterKick = new Dictionary<ZNetPeer, float>(); |
| private static readonly Dictionary<ZNetPeer, float> PeersToDisconnectAfterKick = new Dictionary<ZNetPeer, float>(); |
| |
| |
| public enum ConnectionStatus |
| public enum ConnectionStatus |
| { |
| { |
| None, |
| None, |
| Connecting, |
| Connecting, |
| Connected, |
| Connected, |
| ErrorVersion, |
| ErrorVersion, |
| ErrorDisconnected, |
| ErrorDisconnected, |
| ErrorConnectFailed, |
| ErrorConnectFailed, |
| ErrorPassword, |
| ErrorPassword, |
| ErrorAlreadyConnected, |
| ErrorAlreadyConnected, |
| ErrorBanned, |
| ErrorBanned, |
| ErrorFull, |
| ErrorFull, |
| ErrorPlatformExcluded, |
| ErrorPlatformExcluded, |
| ErrorCrossplayPrivilege, |
| ErrorCrossplayPrivilege, |
| ErrorKicked |
| ErrorKicked |
| } |
| } |
| |
| |
| public struct PlayerInfo |
| public struct PlayerInfo |
| { |
| { |
| public string m_name; |
| public string m_name; |
| |
| |
| public string m_host; |
| public string m_host; |
| |
| |
| public ZDOID m_characterID; |
| public ZDOID m_characterID; |
| |
| |
| public bool m_publicPosition; |
| public bool m_publicPosition; |
| |
| |
| public Vector3 m_position; |
| public Vector3 m_position; |
| } |
| } |
| } |
| } |
| |
| |