| using System; |
| using System; |
| using System.Collections.Generic; |
| using System.Collections.Generic; |
| using System.Linq; |
| using System.Linq; |
| using System.Net; |
| using System.Net; |
| using System.Net.Sockets; |
| using System.Net.Sockets; |
| using Steamworks; |
| using Steamworks; |
| using UnityEngine; |
| using UnityEngine; |
| |
| |
| public class ZSteamMatchmaking |
| public class ZSteamMatchmaking |
| { |
| { |
| public static ZSteamMatchmaking instance |
| public static ZSteamMatchmaking instance |
| { |
| { |
| get |
| get |
| { |
| { |
| return ZSteamMatchmaking.m_instance; |
| return ZSteamMatchmaking.m_instance; |
| } |
| } |
| } |
| } |
| |
| |
| public static void Initialize() |
| public static void Initialize() |
| { |
| { |
| if (ZSteamMatchmaking.m_instance == null) |
| if (ZSteamMatchmaking.m_instance == null) |
| { |
| { |
| ZSteamMatchmaking.m_instance = new ZSteamMatchmaking(); |
| ZSteamMatchmaking.m_instance = new ZSteamMatchmaking(); |
| } |
| } |
| } |
| } |
| |
| |
| private ZSteamMatchmaking() |
| private ZSteamMatchmaking() |
| { |
| { |
| this.m_steamServerCallbackHandler = new ISteamMatchmakingServerListResponse(new ISteamMatchmakingServerListResponse.ServerResponded(this.OnServerResponded), new ISteamMatchmakingServerListResponse.ServerFailedToRespond(this.OnServerFailedToRespond), new ISteamMatchmakingServerListResponse.RefreshComplete(this.OnRefreshComplete)); |
| this.m_steamServerCallbackHandler = new ISteamMatchmakingServerListResponse(new ISteamMatchmakingServerListResponse.ServerResponded(this.OnServerResponded), new ISteamMatchmakingServerListResponse.ServerFailedToRespond(this.OnServerFailedToRespond), new ISteamMatchmakingServerListResponse.RefreshComplete(this.OnRefreshComplete)); |
| this.m_joinServerCallbackHandler = new ISteamMatchmakingPingResponse(new ISteamMatchmakingPingResponse.ServerResponded(this.OnJoinServerRespond), new ISteamMatchmakingPingResponse.ServerFailedToRespond(this.OnJoinServerFailed)); |
| this.m_joinServerCallbackHandler = new ISteamMatchmakingPingResponse(new ISteamMatchmakingPingResponse.ServerResponded(this.OnJoinServerRespond), new ISteamMatchmakingPingResponse.ServerFailedToRespond(this.OnJoinServerFailed)); |
| this.m_lobbyCreated = CallResult<LobbyCreated_t>.Create(new CallResult<LobbyCreated_t>.APIDispatchDelegate(this.OnLobbyCreated)); |
| this.m_lobbyCreated = CallResult<LobbyCreated_t>.Create(new CallResult<LobbyCreated_t>.APIDispatchDelegate(this.OnLobbyCreated)); |
| this.m_lobbyMatchList = CallResult<LobbyMatchList_t>.Create(new CallResult<LobbyMatchList_t>.APIDispatchDelegate(this.OnLobbyMatchList)); |
| this.m_lobbyMatchList = CallResult<LobbyMatchList_t>.Create(new CallResult<LobbyMatchList_t>.APIDispatchDelegate(this.OnLobbyMatchList)); |
| this.m_changeServer = Callback<GameServerChangeRequested_t>.Create(new Callback<GameServerChangeRequested_t>.DispatchDelegate(this.OnChangeServerRequest)); |
| this.m_changeServer = Callback<GameServerChangeRequested_t>.Create(new Callback<GameServerChangeRequested_t>.DispatchDelegate(this.OnChangeServerRequest)); |
| this.m_joinRequest = Callback<GameLobbyJoinRequested_t>.Create(new Callback<GameLobbyJoinRequested_t>.DispatchDelegate(this.OnJoinRequest)); |
| this.m_joinRequest = Callback<GameLobbyJoinRequested_t>.Create(new Callback<GameLobbyJoinRequested_t>.DispatchDelegate(this.OnJoinRequest)); |
| this.m_lobbyDataUpdate = Callback<LobbyDataUpdate_t>.Create(new Callback<LobbyDataUpdate_t>.DispatchDelegate(this.OnLobbyDataUpdate)); |
| this.m_lobbyDataUpdate = Callback<LobbyDataUpdate_t>.Create(new Callback<LobbyDataUpdate_t>.DispatchDelegate(this.OnLobbyDataUpdate)); |
| this.m_authSessionTicketResponse = Callback<GetAuthSessionTicketResponse_t>.Create(new Callback<GetAuthSessionTicketResponse_t>.DispatchDelegate(this.OnAuthSessionTicketResponse)); |
| this.m_authSessionTicketResponse = Callback<GetAuthSessionTicketResponse_t>.Create(new Callback<GetAuthSessionTicketResponse_t>.DispatchDelegate(this.OnAuthSessionTicketResponse)); |
| } |
| } |
| |
| |
| public byte[] RequestSessionTicket(ref SteamNetworkingIdentity serverIdentity) |
| public byte[] RequestSessionTicket(ref SteamNetworkingIdentity serverIdentity) |
| { |
| { |
| this.ReleaseSessionTicket(); |
| this.ReleaseSessionTicket(); |
| byte[] array = new byte[1024]; |
| byte[] array = new byte[1024]; |
| uint num = 0U; |
| uint num = 0U; |
| SteamNetworkingIdentity steamNetworkingIdentity = default(SteamNetworkingIdentity); |
| SteamNetworkingIdentity steamNetworkingIdentity = default(SteamNetworkingIdentity); |
| this.m_authTicket = SteamUser.GetAuthSessionTicket(array, 1024, out num, ref steamNetworkingIdentity); |
| this.m_authTicket = SteamUser.GetAuthSessionTicket(array, 1024, out num, ref steamNetworkingIdentity); |
| if (this.m_authTicket == HAuthTicket.Invalid) |
| if (this.m_authTicket == HAuthTicket.Invalid) |
| { |
| { |
| return null; |
| return null; |
| } |
| } |
| byte[] array2 = new byte[num]; |
| byte[] array2 = new byte[num]; |
| Buffer.BlockCopy(array, 0, array2, 0, (int)num); |
| Buffer.BlockCopy(array, 0, array2, 0, (int)num); |
| return array2; |
| return array2; |
| } |
| } |
| |
| |
| public void ReleaseSessionTicket() |
| public void ReleaseSessionTicket() |
| { |
| { |
| if (this.m_authTicket == HAuthTicket.Invalid) |
| if (this.m_authTicket == HAuthTicket.Invalid) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| SteamUser.CancelAuthTicket(this.m_authTicket); |
| SteamUser.CancelAuthTicket(this.m_authTicket); |
| this.m_authTicket = HAuthTicket.Invalid; |
| this.m_authTicket = HAuthTicket.Invalid; |
| ZLog.Log("Released session ticket"); |
| ZLog.Log("Released session ticket"); |
| } |
| } |
| |
| |
| public bool VerifySessionTicket(byte[] ticket, CSteamID steamID) |
| public bool VerifySessionTicket(byte[] ticket, CSteamID steamID) |
| { |
| { |
| return SteamUser.BeginAuthSession(ticket, ticket.Length, steamID) == EBeginAuthSessionResult.k_EBeginAuthSessionResultOK; |
| return SteamUser.BeginAuthSession(ticket, ticket.Length, steamID) == EBeginAuthSessionResult.k_EBeginAuthSessionResultOK; |
| } |
| } |
| |
| |
| private void OnAuthSessionTicketResponse(GetAuthSessionTicketResponse_t data) |
| private void OnAuthSessionTicketResponse(GetAuthSessionTicketResponse_t data) |
| { |
| { |
| ZLog.Log("Session auth respons callback"); |
| ZLog.Log("Session auth respons callback"); |
| } |
| } |
| |
| |
| private void OnSteamServersConnected(SteamServersConnected_t data) |
| private void OnSteamServersConnected(SteamServersConnected_t data) |
| { |
| { |
| ZLog.Log("Game server connected"); |
| ZLog.Log("Game server connected"); |
| } |
| } |
| |
| |
| private void OnSteamServersDisconnected(SteamServersDisconnected_t data) |
| private void OnSteamServersDisconnected(SteamServersDisconnected_t data) |
| { |
| { |
| ZLog.LogWarning("Game server disconnected"); |
| ZLog.LogWarning("Game server disconnected"); |
| } |
| } |
| |
| |
| private void OnSteamServersConnectFail(SteamServerConnectFailure_t data) |
| private void OnSteamServersConnectFail(SteamServerConnectFailure_t data) |
| { |
| { |
| ZLog.LogWarning("Game server connected failed"); |
| ZLog.LogWarning("Game server connected failed"); |
| } |
| } |
| |
| |
| private void OnChangeServerRequest(GameServerChangeRequested_t data) |
| private void OnChangeServerRequest(GameServerChangeRequested_t data) |
| { |
| { |
| ZLog.Log("ZSteamMatchmaking got change server request to:" + data.m_rgchServer); |
| ZLog.Log("ZSteamMatchmaking got change server request to:" + data.m_rgchServer); |
| this.QueueServerJoin(data.m_rgchServer); |
| this.QueueServerJoin(data.m_rgchServer); |
| } |
| } |
| |
| |
| private void OnJoinRequest(GameLobbyJoinRequested_t data) |
| private void OnJoinRequest(GameLobbyJoinRequested_t data) |
| { |
| { |
| string text = "ZSteamMatchmaking got join request friend:"; |
| string text = "ZSteamMatchmaking got join request friend:"; |
| CSteamID csteamID = data.m_steamIDFriend; |
| CSteamID csteamID = data.m_steamIDFriend; |
| string text2 = csteamID.ToString(); |
| string text2 = csteamID.ToString(); |
| string text3 = " lobby:"; |
| string text3 = " lobby:"; |
| csteamID = data.m_steamIDLobby; |
| csteamID = data.m_steamIDLobby; |
| ZLog.Log(text + text2 + text3 + csteamID.ToString()); |
| ZLog.Log(text + text2 + text3 + csteamID.ToString()); |
| this.QueueLobbyJoin(data.m_steamIDLobby); |
| this.QueueLobbyJoin(data.m_steamIDLobby); |
| } |
| } |
| |
| |
| private IPAddress FindIP(string host) |
| private IPAddress FindIP(string host) |
| { |
| { |
| IPAddress ipaddress2; |
| IPAddress ipaddress2; |
| try |
| try |
| { |
| { |
| IPAddress ipaddress; |
| IPAddress ipaddress; |
| if (IPAddress.TryParse(host, out ipaddress)) |
| if (IPAddress.TryParse(host, out ipaddress)) |
| { |
| { |
| ipaddress2 = ipaddress; |
| ipaddress2 = ipaddress; |
| } |
| } |
| else |
| else |
| { |
| { |
| ZLog.Log("Not an ip address " + host + " doing dns lookup"); |
| ZLog.Log("Not an ip address " + host + " doing dns lookup"); |
| IPHostEntry hostEntry = Dns.GetHostEntry(host); |
| IPHostEntry hostEntry = Dns.GetHostEntry(host); |
| if (hostEntry.AddressList.Length == 0) |
| if (hostEntry.AddressList.Length == 0) |
| { |
| { |
| ZLog.Log("Dns lookup failed"); |
| ZLog.Log("Dns lookup failed"); |
| ipaddress2 = null; |
| ipaddress2 = null; |
| } |
| } |
| else |
| else |
| { |
| { |
| ZLog.Log("Got dns entries: " + hostEntry.AddressList.Length.ToString()); |
| ZLog.Log("Got dns entries: " + hostEntry.AddressList.Length.ToString()); |
| foreach (IPAddress ipaddress3 in hostEntry.AddressList) |
| foreach (IPAddress ipaddress3 in hostEntry.AddressList) |
| { |
| { |
| if (ipaddress3.AddressFamily == AddressFamily.InterNetwork) |
| if (ipaddress3.AddressFamily == AddressFamily.InterNetwork) |
| { |
| { |
| return ipaddress3; |
| return ipaddress3; |
| } |
| } |
| } |
| } |
| ipaddress2 = null; |
| ipaddress2 = null; |
| } |
| } |
| } |
| } |
| } |
| } |
| catch (Exception ex) |
| catch (Exception ex) |
| { |
| { |
| ZLog.Log("Exception while finding ip:" + ex.ToString()); |
| ZLog.Log("Exception while finding ip:" + ex.ToString()); |
| ipaddress2 = null; |
| ipaddress2 = null; |
| } |
| } |
| return ipaddress2; |
| return ipaddress2; |
| } |
| } |
| |
| |
| public bool ResolveIPFromAddrString(string addr, ref SteamNetworkingIPAddr destination) |
| public bool ResolveIPFromAddrString(string addr, ref SteamNetworkingIPAddr destination) |
| { |
| { |
| bool flag; |
| bool flag; |
| try |
| try |
| { |
| { |
| string[] array = addr.Split(':', StringSplitOptions.None); |
| string[] array = addr.Split(':', StringSplitOptions.None); |
| if (array.Length < 2) |
| if (array.Length < 2) |
| { |
| { |
| flag = false; |
| flag = false; |
| } |
| } |
| else |
| else |
| { |
| { |
| IPAddress ipaddress = this.FindIP(array[0]); |
| IPAddress ipaddress = this.FindIP(array[0]); |
| if (ipaddress == null) |
| if (ipaddress == null) |
| { |
| { |
| ZLog.Log("Invalid address " + array[0]); |
| ZLog.Log("Invalid address " + array[0]); |
| flag = false; |
| flag = false; |
| } |
| } |
| else |
| else |
| { |
| { |
| uint num = (uint)IPAddress.HostToNetworkOrder(BitConverter.ToInt32(ipaddress.GetAddressBytes(), 0)); |
| uint num = (uint)IPAddress.HostToNetworkOrder(BitConverter.ToInt32(ipaddress.GetAddressBytes(), 0)); |
| int num2 = int.Parse(array[1]); |
| int num2 = int.Parse(array[1]); |
| ZLog.Log("connect to ip:" + ipaddress.ToString() + " port:" + num2.ToString()); |
| ZLog.Log("connect to ip:" + ipaddress.ToString() + " port:" + num2.ToString()); |
| destination.SetIPv4(num, (ushort)num2); |
| destination.SetIPv4(num, (ushort)num2); |
| flag = true; |
| flag = true; |
| } |
| } |
| } |
| } |
| } |
| } |
| catch (Exception ex) |
| catch (Exception ex) |
| { |
| { |
| string text = "Exception when resolving IP address: "; |
| string text = "Exception when resolving IP address: "; |
| Exception ex2 = ex; |
| Exception ex2 = ex; |
| ZLog.Log(text + ((ex2 != null) ? ex2.ToString() : null)); |
| ZLog.Log(text + ((ex2 != null) ? ex2.ToString() : null)); |
| flag = false; |
| flag = false; |
| } |
| } |
| return flag; |
| return flag; |
| } |
| } |
| |
| |
| public void QueueServerJoin(string addr) |
| public void QueueServerJoin(string addr) |
| { |
| { |
| SteamNetworkingIPAddr steamNetworkingIPAddr = default(SteamNetworkingIPAddr); |
| SteamNetworkingIPAddr steamNetworkingIPAddr = default(SteamNetworkingIPAddr); |
| if (this.ResolveIPFromAddrString(addr, ref steamNetworkingIPAddr)) |
| if (this.ResolveIPFromAddrString(addr, ref steamNetworkingIPAddr)) |
| { |
| { |
| this.m_joinData = new ServerJoinDataDedicated(steamNetworkingIPAddr.GetIPv4(), steamNetworkingIPAddr.m_port); |
| this.m_joinData = new ServerJoinDataDedicated(steamNetworkingIPAddr.GetIPv4(), steamNetworkingIPAddr.m_port); |
| return; |
| return; |
| } |
| } |
| ZLog.Log("Couldn't resolve IP address."); |
| ZLog.Log("Couldn't resolve IP address."); |
| } |
| } |
| |
| |
| private void OnJoinServerRespond(gameserveritem_t serverData) |
| private void OnJoinServerRespond(gameserveritem_t serverData) |
| { |
| { |
| string text = "Got join server data "; |
| string text = "Got join server data "; |
| string serverName = serverData.GetServerName(); |
| string serverName = serverData.GetServerName(); |
| string text2 = " "; |
| string text2 = " "; |
| CSteamID steamID = serverData.m_steamID; |
| CSteamID steamID = serverData.m_steamID; |
| ZLog.Log(text + serverName + text2 + steamID.ToString()); |
| ZLog.Log(text + serverName + text2 + steamID.ToString()); |
| SteamNetworkingIPAddr steamNetworkingIPAddr = default(SteamNetworkingIPAddr); |
| SteamNetworkingIPAddr steamNetworkingIPAddr = default(SteamNetworkingIPAddr); |
| steamNetworkingIPAddr.SetIPv4(serverData.m_NetAdr.GetIP(), serverData.m_NetAdr.GetConnectionPort()); |
| steamNetworkingIPAddr.SetIPv4(serverData.m_NetAdr.GetIP(), serverData.m_NetAdr.GetConnectionPort()); |
| this.m_joinData = new ServerJoinDataDedicated(steamNetworkingIPAddr.GetIPv4(), steamNetworkingIPAddr.m_port); |
| this.m_joinData = new ServerJoinDataDedicated(steamNetworkingIPAddr.GetIPv4(), steamNetworkingIPAddr.m_port); |
| } |
| } |
| |
| |
| private void OnJoinServerFailed() |
| private void OnJoinServerFailed() |
| { |
| { |
| ZLog.Log("Failed to get join server data"); |
| ZLog.Log("Failed to get join server data"); |
| } |
| } |
| |
| |
| private bool TryGetLobbyData(CSteamID lobbyID) |
| private bool TryGetLobbyData(CSteamID lobbyID) |
| { |
| { |
| uint num; |
| uint num; |
| ushort num2; |
| ushort num2; |
| CSteamID csteamID; |
| CSteamID csteamID; |
| if (!SteamMatchmaking.GetLobbyGameServer(lobbyID, out num, out num2, out csteamID)) |
| if (!SteamMatchmaking.GetLobbyGameServer(lobbyID, out num, out num2, out csteamID)) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| string text = " hostid: "; |
| string text = " hostid: "; |
| CSteamID csteamID2 = csteamID; |
| CSteamID csteamID2 = csteamID; |
| ZLog.Log(text + csteamID2.ToString()); |
| ZLog.Log(text + csteamID2.ToString()); |
| this.m_queuedJoinLobby = CSteamID.Nil; |
| this.m_queuedJoinLobby = CSteamID.Nil; |
| ServerStatus lobbyServerData = this.GetLobbyServerData(lobbyID); |
| ServerStatus lobbyServerData = this.GetLobbyServerData(lobbyID); |
| this.m_joinData = lobbyServerData.m_joinData; |
| this.m_joinData = lobbyServerData.m_joinData; |
| return true; |
| return true; |
| } |
| } |
| |
| |
| public void QueueLobbyJoin(CSteamID lobbyID) |
| public void QueueLobbyJoin(CSteamID lobbyID) |
| { |
| { |
| if (!this.TryGetLobbyData(lobbyID)) |
| if (!this.TryGetLobbyData(lobbyID)) |
| { |
| { |
| string text = "Failed to get lobby data for lobby "; |
| string text = "Failed to get lobby data for lobby "; |
| CSteamID csteamID = lobbyID; |
| CSteamID csteamID = lobbyID; |
| ZLog.Log(text + csteamID.ToString() + ", requesting lobby data"); |
| ZLog.Log(text + csteamID.ToString() + ", requesting lobby data"); |
| this.m_queuedJoinLobby = lobbyID; |
| this.m_queuedJoinLobby = lobbyID; |
| SteamMatchmaking.RequestLobbyData(lobbyID); |
| SteamMatchmaking.RequestLobbyData(lobbyID); |
| } |
| } |
| if (FejdStartup.instance == null) |
| if (FejdStartup.instance == null) |
| { |
| { |
| if (UnifiedPopup.IsAvailable() && Menu.instance != null) |
| if (UnifiedPopup.IsAvailable() && Menu.instance != null) |
| { |
| { |
| UnifiedPopup.Push(new YesNoPopup("$menu_joindifferentserver", "$menu_logoutprompt", delegate |
| UnifiedPopup.Push(new YesNoPopup("$menu_joindifferentserver", "$menu_logoutprompt", delegate |
| { |
| { |
| UnifiedPopup.Pop(); |
| UnifiedPopup.Pop(); |
| if (Menu.instance != null) |
| if (Menu.instance != null) |
| { |
| { |
| Menu.instance.OnLogoutYes(); |
| Menu.instance.OnLogoutYes(); |
| } |
| } |
| }, delegate |
| }, delegate |
| { |
| { |
| UnifiedPopup.Pop(); |
| UnifiedPopup.Pop(); |
| this.m_queuedJoinLobby = CSteamID.Nil; |
| this.m_queuedJoinLobby = CSteamID.Nil; |
| this.m_joinData = null; |
| this.m_joinData = null; |
| }, true)); |
| }, true)); |
| return; |
| return; |
| } |
| } |
| Debug.LogWarning("Couldn't handle invite appropriately! Ignoring."); |
| Debug.LogWarning("Couldn't handle invite appropriately! Ignoring."); |
| this.m_queuedJoinLobby = CSteamID.Nil; |
| this.m_queuedJoinLobby = CSteamID.Nil; |
| this.m_joinData = null; |
| this.m_joinData = null; |
| } |
| } |
| } |
| } |
| |
| |
| private void OnLobbyDataUpdate(LobbyDataUpdate_t data) |
| private void OnLobbyDataUpdate(LobbyDataUpdate_t data) |
| { |
| { |
| CSteamID csteamID = new CSteamID(data.m_ulSteamIDLobby); |
| CSteamID csteamID = new CSteamID(data.m_ulSteamIDLobby); |
| if (csteamID == this.m_queuedJoinLobby) |
| if (csteamID == this.m_queuedJoinLobby) |
| { |
| { |
| if (this.TryGetLobbyData(csteamID)) |
| if (this.TryGetLobbyData(csteamID)) |
| { |
| { |
| ZLog.Log("Got lobby data, for queued lobby"); |
| ZLog.Log("Got lobby data, for queued lobby"); |
| return; |
| return; |
| } |
| } |
| } |
| } |
| else |
| else |
| { |
| { |
| ZLog.Log("Got requested lobby data"); |
| ZLog.Log("Got requested lobby data"); |
| foreach (KeyValuePair<CSteamID, string> keyValuePair in this.m_requestedFriendGames) |
| foreach (KeyValuePair<CSteamID, string> keyValuePair in this.m_requestedFriendGames) |
| { |
| { |
| if (keyValuePair.Key == csteamID) |
| if (keyValuePair.Key == csteamID) |
| { |
| { |
| ServerStatus lobbyServerData = this.GetLobbyServerData(csteamID); |
| ServerStatus lobbyServerData = this.GetLobbyServerData(csteamID); |
| if (lobbyServerData != null) |
| if (lobbyServerData != null) |
| { |
| { |
| lobbyServerData.m_joinData.m_serverName = keyValuePair.Value + " [" + lobbyServerData.m_joinData.m_serverName + "]"; |
| lobbyServerData.m_joinData.m_serverName = keyValuePair.Value + " [" + lobbyServerData.m_joinData.m_serverName + "]"; |
| this.m_friendServers.Add(lobbyServerData); |
| this.m_friendServers.Add(lobbyServerData); |
| this.m_serverListRevision++; |
| this.m_serverListRevision++; |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| public void RegisterServer(string name, bool password, GameVersion gameVersion, List<string> modifiers, uint networkVersion, bool publicServer, string worldName, ZSteamMatchmaking.ServerRegistered serverRegisteredCallback) |
| public void RegisterServer(string name, bool password, GameVersion gameVersion, List<string> modifiers, uint networkVersion, bool publicServer, string worldName, ZSteamMatchmaking.ServerRegistered serverRegisteredCallback) |
| { |
| { |
| this.UnregisterServer(); |
| this.UnregisterServer(); |
| this.serverRegisteredCallback = serverRegisteredCallback; |
| this.serverRegisteredCallback = serverRegisteredCallback; |
| SteamAPICall_t steamAPICall_t = SteamMatchmaking.CreateLobby(publicServer ? ELobbyType.k_ELobbyTypePublic : ELobbyType.k_ELobbyTypeFriendsOnly, 32); |
| SteamAPICall_t steamAPICall_t = SteamMatchmaking.CreateLobby(publicServer ? ELobbyType.k_ELobbyTypePublic : ELobbyType.k_ELobbyTypeFriendsOnly, 32); |
| this.m_lobbyCreated.Set(steamAPICall_t, null); |
| this.m_lobbyCreated.Set(steamAPICall_t, null); |
| this.m_registerServerName = name; |
| this.m_registerServerName = name; |
| this.m_registerPassword = password; |
| this.m_registerPassword = password; |
| this.m_registerGameVerson = gameVersion; |
| this.m_registerGameVerson = gameVersion; |
| this.m_registerNetworkVerson = networkVersion; |
| this.m_registerNetworkVerson = networkVersion; |
| this.m_registerModifiers = modifiers; |
| this.m_registerModifiers = modifiers; |
| ZLog.Log("Registering lobby"); |
| ZLog.Log("Registering lobby"); |
| } |
| } |
| |
| |
| private void OnLobbyCreated(LobbyCreated_t data, bool ioError) |
| private void OnLobbyCreated(LobbyCreated_t data, bool ioError) |
| { |
| { |
| ZLog.Log(string.Concat(new string[] |
| ZLog.Log(string.Concat(new string[] |
| { |
| { |
| "Lobby was created ", |
| "Lobby was created ", |
| data.m_eResult.ToString(), |
| data.m_eResult.ToString(), |
| " ", |
| " ", |
| data.m_ulSteamIDLobby.ToString(), |
| data.m_ulSteamIDLobby.ToString(), |
| " error:", |
| " error:", |
| ioError.ToString() |
| ioError.ToString() |
| })); |
| })); |
| if (ioError) |
| if (ioError) |
| { |
| { |
| ZSteamMatchmaking.ServerRegistered serverRegistered = this.serverRegisteredCallback; |
| ZSteamMatchmaking.ServerRegistered serverRegistered = this.serverRegisteredCallback; |
| if (serverRegistered == null) |
| if (serverRegistered == null) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| serverRegistered(false); |
| serverRegistered(false); |
| return; |
| return; |
| } |
| } |
| else if (data.m_eResult == EResult.k_EResultNoConnection) |
| else if (data.m_eResult == EResult.k_EResultNoConnection) |
| { |
| { |
| ZLog.LogWarning("Failed to connect to Steam to register the server!"); |
| ZLog.LogWarning("Failed to connect to Steam to register the server!"); |
| ZSteamMatchmaking.ServerRegistered serverRegistered2 = this.serverRegisteredCallback; |
| ZSteamMatchmaking.ServerRegistered serverRegistered2 = this.serverRegisteredCallback; |
| if (serverRegistered2 == null) |
| if (serverRegistered2 == null) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| serverRegistered2(false); |
| serverRegistered2(false); |
| return; |
| return; |
| } |
| } |
| else |
| else |
| { |
| { |
| this.m_myLobby = new CSteamID(data.m_ulSteamIDLobby); |
| this.m_myLobby = new CSteamID(data.m_ulSteamIDLobby); |
| if (!SteamMatchmaking.SetLobbyData(this.m_myLobby, "name", this.m_registerServerName)) |
| if (!SteamMatchmaking.SetLobbyData(this.m_myLobby, "name", this.m_registerServerName)) |
| { |
| { |
| Debug.LogError("Couldn't set name in lobby"); |
| Debug.LogError("Couldn't set name in lobby"); |
| } |
| } |
| if (!SteamMatchmaking.SetLobbyData(this.m_myLobby, "password", this.m_registerPassword ? "1" : "0")) |
| if (!SteamMatchmaking.SetLobbyData(this.m_myLobby, "password", this.m_registerPassword ? "1" : "0")) |
| { |
| { |
| Debug.LogError("Couldn't set password in lobby"); |
| Debug.LogError("Couldn't set password in lobby"); |
| } |
| } |
| if (!SteamMatchmaking.SetLobbyData(this.m_myLobby, "version", this.m_registerGameVerson.ToString())) |
| if (!SteamMatchmaking.SetLobbyData(this.m_myLobby, "version", this.m_registerGameVerson.ToString())) |
| { |
| { |
| Debug.LogError("Couldn't set game version in lobby"); |
| Debug.LogError("Couldn't set game version in lobby"); |
| } |
| } |
| if (!SteamMatchmaking.SetLobbyData(this.m_myLobby, "networkversion", this.m_registerNetworkVerson.ToString())) |
| if (!SteamMatchmaking.SetLobbyData(this.m_myLobby, "networkversion", this.m_registerNetworkVerson.ToString())) |
| { |
| { |
| Debug.LogError("Couldn't set network version in lobby"); |
| Debug.LogError("Couldn't set network version in lobby"); |
| } |
| } |
| if (!SteamMatchmaking.SetLobbyData(this.m_myLobby, "modifiers", StringUtils.EncodeStringListAsString(this.m_registerModifiers, true))) |
| if (!SteamMatchmaking.SetLobbyData(this.m_myLobby, "modifiers", StringUtils.EncodeStringListAsString(this.m_registerModifiers, true))) |
| { |
| { |
| Debug.LogError("Couldn't set modifiers in lobby"); |
| Debug.LogError("Couldn't set modifiers in lobby"); |
| } |
| } |
| OnlineBackendType onlineBackend = ZNet.m_onlineBackend; |
| OnlineBackendType onlineBackend = ZNet.m_onlineBackend; |
| string text; |
| string text; |
| string text2; |
| string text2; |
| string text3; |
| string text3; |
| if (onlineBackend == OnlineBackendType.CustomSocket) |
| if (onlineBackend == OnlineBackendType.CustomSocket) |
| { |
| { |
| text = "Dedicated"; |
| text = "Dedicated"; |
| text2 = ZNet.GetServerString(false); |
| text2 = ZNet.GetServerString(false); |
| text3 = "1"; |
| text3 = "1"; |
| } |
| } |
| else if (onlineBackend == OnlineBackendType.Steamworks) |
| else if (onlineBackend == OnlineBackendType.Steamworks) |
| { |
| { |
| text = "Steam user"; |
| text = "Steam user"; |
| text2 = ""; |
| text2 = ""; |
| text3 = "0"; |
| text3 = "0"; |
| } |
| } |
| else if (onlineBackend == OnlineBackendType.PlayFab) |
| else if (onlineBackend == OnlineBackendType.PlayFab) |
| { |
| { |
| text = "PlayFab user"; |
| text = "PlayFab user"; |
| text2 = PlayFabManager.instance.Entity.Id; |
| text2 = PlayFabManager.instance.Entity.Id; |
| text3 = "1"; |
| text3 = "1"; |
| } |
| } |
| else |
| else |
| { |
| { |
| Debug.LogError("Can't create lobby for server with unknown or unsupported backend"); |
| Debug.LogError("Can't create lobby for server with unknown or unsupported backend"); |
| text = ""; |
| text = ""; |
| text2 = ""; |
| text2 = ""; |
| text3 = ""; |
| text3 = ""; |
| } |
| } |
| if (!PrivilegeManager.CanCrossplay) |
| if (!PrivilegeManager.CanCrossplay) |
| { |
| { |
| text3 = "0"; |
| text3 = "0"; |
| } |
| } |
| if (!SteamMatchmaking.SetLobbyData(this.m_myLobby, "serverType", text)) |
| if (!SteamMatchmaking.SetLobbyData(this.m_myLobby, "serverType", text)) |
| { |
| { |
| Debug.LogError("Couldn't set backend in lobby"); |
| Debug.LogError("Couldn't set backend in lobby"); |
| } |
| } |
| if (!SteamMatchmaking.SetLobbyData(this.m_myLobby, "hostID", text2)) |
| if (!SteamMatchmaking.SetLobbyData(this.m_myLobby, "hostID", text2)) |
| { |
| { |
| Debug.LogError("Couldn't set host in lobby"); |
| Debug.LogError("Couldn't set host in lobby"); |
| } |
| } |
| if (!SteamMatchmaking.SetLobbyData(this.m_myLobby, "isCrossplay", text3)) |
| if (!SteamMatchmaking.SetLobbyData(this.m_myLobby, "isCrossplay", text3)) |
| { |
| { |
| Debug.LogError("Couldn't set crossplay in lobby"); |
| Debug.LogError("Couldn't set crossplay in lobby"); |
| } |
| } |
| SteamMatchmaking.SetLobbyGameServer(this.m_myLobby, 0U, 0, SteamUser.GetSteamID()); |
| SteamMatchmaking.SetLobbyGameServer(this.m_myLobby, 0U, 0, SteamUser.GetSteamID()); |
| ZSteamMatchmaking.ServerRegistered serverRegistered3 = this.serverRegisteredCallback; |
| ZSteamMatchmaking.ServerRegistered serverRegistered3 = this.serverRegisteredCallback; |
| if (serverRegistered3 == null) |
| if (serverRegistered3 == null) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| serverRegistered3(true); |
| serverRegistered3(true); |
| return; |
| return; |
| } |
| } |
| } |
| } |
| |
| |
| private void OnLobbyEnter(LobbyEnter_t data, bool ioError) |
| private void OnLobbyEnter(LobbyEnter_t data, bool ioError) |
| { |
| { |
| ZLog.LogWarning("Entering lobby " + data.m_ulSteamIDLobby.ToString()); |
| ZLog.LogWarning("Entering lobby " + data.m_ulSteamIDLobby.ToString()); |
| } |
| } |
| |
| |
| public void UnregisterServer() |
| public void UnregisterServer() |
| { |
| { |
| if (this.m_myLobby != CSteamID.Nil) |
| if (this.m_myLobby != CSteamID.Nil) |
| { |
| { |
| SteamMatchmaking.SetLobbyJoinable(this.m_myLobby, false); |
| SteamMatchmaking.SetLobbyJoinable(this.m_myLobby, false); |
| SteamMatchmaking.LeaveLobby(this.m_myLobby); |
| SteamMatchmaking.LeaveLobby(this.m_myLobby); |
| this.m_myLobby = CSteamID.Nil; |
| this.m_myLobby = CSteamID.Nil; |
| } |
| } |
| } |
| } |
| |
| |
| public void RequestServerlist() |
| public void RequestServerlist() |
| { |
| { |
| this.IsRefreshing = true; |
| this.IsRefreshing = true; |
| this.RequestFriendGames(); |
| this.RequestFriendGames(); |
| this.RequestPublicLobbies(); |
| this.RequestPublicLobbies(); |
| this.RequestDedicatedServers(); |
| this.RequestDedicatedServers(); |
| } |
| } |
| |
| |
| public void StopServerListing() |
| public void StopServerListing() |
| { |
| { |
| if (this.m_haveListRequest) |
| if (this.m_haveListRequest) |
| { |
| { |
| SteamMatchmakingServers.ReleaseRequest(this.m_serverListRequest); |
| SteamMatchmakingServers.ReleaseRequest(this.m_serverListRequest); |
| this.m_haveListRequest = false; |
| this.m_haveListRequest = false; |
| this.IsRefreshing = false; |
| this.IsRefreshing = false; |
| } |
| } |
| } |
| } |
| |
| |
| private void RequestFriendGames() |
| private void RequestFriendGames() |
| { |
| { |
| this.m_friendServers.Clear(); |
| this.m_friendServers.Clear(); |
| this.m_requestedFriendGames.Clear(); |
| this.m_requestedFriendGames.Clear(); |
| int num = SteamFriends.GetFriendCount(EFriendFlags.k_EFriendFlagImmediate); |
| int num = SteamFriends.GetFriendCount(EFriendFlags.k_EFriendFlagImmediate); |
| if (num == -1) |
| if (num == -1) |
| { |
| { |
| ZLog.Log("GetFriendCount returned -1, the current user is not logged in."); |
| ZLog.Log("GetFriendCount returned -1, the current user is not logged in."); |
| num = 0; |
| num = 0; |
| } |
| } |
| for (int i = 0; i < num; i++) |
| for (int i = 0; i < num; i++) |
| { |
| { |
| CSteamID friendByIndex = SteamFriends.GetFriendByIndex(i, EFriendFlags.k_EFriendFlagImmediate); |
| CSteamID friendByIndex = SteamFriends.GetFriendByIndex(i, EFriendFlags.k_EFriendFlagImmediate); |
| string friendPersonaName = SteamFriends.GetFriendPersonaName(friendByIndex); |
| string friendPersonaName = SteamFriends.GetFriendPersonaName(friendByIndex); |
| FriendGameInfo_t friendGameInfo_t; |
| FriendGameInfo_t friendGameInfo_t; |
| if (SteamFriends.GetFriendGamePlayed(friendByIndex, out friendGameInfo_t) && friendGameInfo_t.m_gameID == (CGameID)((ulong)SteamManager.APP_ID) && friendGameInfo_t.m_steamIDLobby != CSteamID.Nil) |
| if (SteamFriends.GetFriendGamePlayed(friendByIndex, out friendGameInfo_t) && friendGameInfo_t.m_gameID == (CGameID)((ulong)SteamManager.APP_ID) && friendGameInfo_t.m_steamIDLobby != CSteamID.Nil) |
| { |
| { |
| ZLog.Log("Friend is in our game"); |
| ZLog.Log("Friend is in our game"); |
| this.m_requestedFriendGames.Add(new KeyValuePair<CSteamID, string>(friendGameInfo_t.m_steamIDLobby, friendPersonaName)); |
| this.m_requestedFriendGames.Add(new KeyValuePair<CSteamID, string>(friendGameInfo_t.m_steamIDLobby, friendPersonaName)); |
| SteamMatchmaking.RequestLobbyData(friendGameInfo_t.m_steamIDLobby); |
| SteamMatchmaking.RequestLobbyData(friendGameInfo_t.m_steamIDLobby); |
| } |
| } |
| } |
| } |
| this.m_serverListRevision++; |
| this.m_serverListRevision++; |
| } |
| } |
| |
| |
| private void RequestPublicLobbies() |
| private void RequestPublicLobbies() |
| { |
| { |
| SteamAPICall_t steamAPICall_t = SteamMatchmaking.RequestLobbyList(); |
| SteamAPICall_t steamAPICall_t = SteamMatchmaking.RequestLobbyList(); |
| this.m_lobbyMatchList.Set(steamAPICall_t, null); |
| this.m_lobbyMatchList.Set(steamAPICall_t, null); |
| this.m_refreshingPublicGames = true; |
| this.m_refreshingPublicGames = true; |
| } |
| } |
| |
| |
| private void RequestDedicatedServers() |
| private void RequestDedicatedServers() |
| { |
| { |
| if (this.m_haveListRequest) |
| if (this.m_haveListRequest) |
| { |
| { |
| SteamMatchmakingServers.ReleaseRequest(this.m_serverListRequest); |
| SteamMatchmakingServers.ReleaseRequest(this.m_serverListRequest); |
| this.m_haveListRequest = false; |
| this.m_haveListRequest = false; |
| } |
| } |
| this.m_dedicatedServers.Clear(); |
| this.m_dedicatedServers.Clear(); |
| this.m_serverListRequest = SteamMatchmakingServers.RequestInternetServerList(SteamUtils.GetAppID(), new MatchMakingKeyValuePair_t[0], 0U, this.m_steamServerCallbackHandler); |
| this.m_serverListRequest = SteamMatchmakingServers.RequestInternetServerList(SteamUtils.GetAppID(), new MatchMakingKeyValuePair_t[0], 0U, this.m_steamServerCallbackHandler); |
| this.m_haveListRequest = true; |
| this.m_haveListRequest = true; |
| } |
| } |
| |
| |
| private void OnLobbyMatchList(LobbyMatchList_t data, bool ioError) |
| private void OnLobbyMatchList(LobbyMatchList_t data, bool ioError) |
| { |
| { |
| this.m_refreshingPublicGames = false; |
| this.m_refreshingPublicGames = false; |
| this.m_matchmakingServers.Clear(); |
| this.m_matchmakingServers.Clear(); |
| int num = 0; |
| int num = 0; |
| while ((long)num < (long)((ulong)data.m_nLobbiesMatching)) |
| while ((long)num < (long)((ulong)data.m_nLobbiesMatching)) |
| { |
| { |
| CSteamID lobbyByIndex = SteamMatchmaking.GetLobbyByIndex(num); |
| CSteamID lobbyByIndex = SteamMatchmaking.GetLobbyByIndex(num); |
| ServerStatus lobbyServerData = this.GetLobbyServerData(lobbyByIndex); |
| ServerStatus lobbyServerData = this.GetLobbyServerData(lobbyByIndex); |
| if (lobbyServerData != null) |
| if (lobbyServerData != null) |
| { |
| { |
| this.m_matchmakingServers.Add(lobbyServerData); |
| this.m_matchmakingServers.Add(lobbyServerData); |
| } |
| } |
| num++; |
| num++; |
| } |
| } |
| this.m_serverListRevision++; |
| this.m_serverListRevision++; |
| } |
| } |
| |
| |
| private ServerStatus GetLobbyServerData(CSteamID lobbyID) |
| private ServerStatus GetLobbyServerData(CSteamID lobbyID) |
| { |
| { |
| string lobbyData = SteamMatchmaking.GetLobbyData(lobbyID, "name"); |
| string lobbyData = SteamMatchmaking.GetLobbyData(lobbyID, "name"); |
| bool flag = SteamMatchmaking.GetLobbyData(lobbyID, "password") == "1"; |
| bool flag = SteamMatchmaking.GetLobbyData(lobbyID, "password") == "1"; |
| GameVersion gameVersion = GameVersion.ParseGameVersion(SteamMatchmaking.GetLobbyData(lobbyID, "version")); |
| GameVersion gameVersion = GameVersion.ParseGameVersion(SteamMatchmaking.GetLobbyData(lobbyID, "version")); |
| List<string> list; |
| List<string> list; |
| StringUtils.TryDecodeStringAsICollection<List<string>>(SteamMatchmaking.GetLobbyData(lobbyID, "modifiers"), out list); |
| StringUtils.TryDecodeStringAsICollection<List<string>>(SteamMatchmaking.GetLobbyData(lobbyID, "modifiers"), out list); |
| uint num = (uint.TryParse(SteamMatchmaking.GetLobbyData(lobbyID, "networkversion"), out num) ? num : 0U); |
| uint num = (uint.TryParse(SteamMatchmaking.GetLobbyData(lobbyID, "networkversion"), out num) ? num : 0U); |
| int numLobbyMembers = SteamMatchmaking.GetNumLobbyMembers(lobbyID); |
| int numLobbyMembers = SteamMatchmaking.GetNumLobbyMembers(lobbyID); |
| uint num2; |
| uint num2; |
| ushort num3; |
| ushort num3; |
| CSteamID csteamID; |
| CSteamID csteamID; |
| if (SteamMatchmaking.GetLobbyGameServer(lobbyID, out num2, out num3, out csteamID)) |
| if (SteamMatchmaking.GetLobbyGameServer(lobbyID, out num2, out num3, out csteamID)) |
| { |
| { |
| string lobbyData2 = SteamMatchmaking.GetLobbyData(lobbyID, "hostID"); |
| string lobbyData2 = SteamMatchmaking.GetLobbyData(lobbyID, "hostID"); |
| string lobbyData3 = SteamMatchmaking.GetLobbyData(lobbyID, "serverType"); |
| string lobbyData3 = SteamMatchmaking.GetLobbyData(lobbyID, "serverType"); |
| string lobbyData4 = SteamMatchmaking.GetLobbyData(lobbyID, "isCrossplay"); |
| string lobbyData4 = SteamMatchmaking.GetLobbyData(lobbyID, "isCrossplay"); |
| ServerStatus serverStatus; |
| ServerStatus serverStatus; |
| if (lobbyData3 == null || lobbyData3.Length != 0) |
| if (lobbyData3 == null || lobbyData3.Length != 0) |
| { |
| { |
| if (!(lobbyData3 == "Steam user")) |
| if (!(lobbyData3 == "Steam user")) |
| { |
| { |
| if (!(lobbyData3 == "PlayFab user")) |
| if (!(lobbyData3 == "PlayFab user")) |
| { |
| { |
| if (!(lobbyData3 == "Dedicated")) |
| if (!(lobbyData3 == "Dedicated")) |
| { |
| { |
| ZLog.LogError("Couldn't get lobby data for unknown backend \"" + lobbyData3 + "\"! " + this.KnownBackendsString()); |
| ZLog.LogError("Couldn't get lobby data for unknown backend \"" + lobbyData3 + "\"! " + this.KnownBackendsString()); |
| return null; |
| return null; |
| } |
| } |
| ServerJoinDataDedicated serverJoinDataDedicated = new ServerJoinDataDedicated(lobbyData2); |
| ServerJoinDataDedicated serverJoinDataDedicated = new ServerJoinDataDedicated(lobbyData2); |
| if (!serverJoinDataDedicated.IsValid()) |
| if (!serverJoinDataDedicated.IsValid()) |
| { |
| { |
| return null; |
| return null; |
| } |
| } |
| serverStatus = new ServerStatus(serverJoinDataDedicated); |
| serverStatus = new ServerStatus(serverJoinDataDedicated); |
| } |
| } |
| else |
| else |
| { |
| { |
| serverStatus = new ServerStatus(new ServerJoinDataPlayFabUser(lobbyData2)); |
| serverStatus = new ServerStatus(new ServerJoinDataPlayFabUser(lobbyData2)); |
| if (!serverStatus.m_joinData.IsValid()) |
| if (!serverStatus.m_joinData.IsValid()) |
| { |
| { |
| return null; |
| return null; |
| } |
| } |
| } |
| } |
| } |
| } |
| else |
| else |
| { |
| { |
| serverStatus = new ServerStatus(new ServerJoinDataSteamUser(csteamID)); |
| serverStatus = new ServerStatus(new ServerJoinDataSteamUser(csteamID)); |
| } |
| } |
| } |
| } |
| else |
| else |
| { |
| { |
| serverStatus = new ServerStatus(new ServerJoinDataSteamUser(csteamID)); |
| serverStatus = new ServerStatus(new ServerJoinDataSteamUser(csteamID)); |
| } |
| } |
| serverStatus.UpdateStatus(OnlineStatus.Online, lobbyData, (uint)numLobbyMembers, gameVersion, list, num, flag, (lobbyData4 == "1") ? PrivilegeManager.Platform.None : PrivilegeManager.Platform.Steam, serverStatus.m_hostId, true); |
| serverStatus.UpdateStatus(OnlineStatus.Online, lobbyData, (uint)numLobbyMembers, gameVersion, list, num, flag, (lobbyData4 == "1") ? PrivilegeManager.Platform.None : PrivilegeManager.Platform.Steam, serverStatus.m_hostId, true); |
| return serverStatus; |
| return serverStatus; |
| } |
| } |
| ZLog.Log("Failed to get lobby gameserver"); |
| ZLog.Log("Failed to get lobby gameserver"); |
| return null; |
| return null; |
| } |
| } |
| |
| |
| public string KnownBackendsString() |
| public string KnownBackendsString() |
| { |
| { |
| List<string> list = new List<string>(); |
| List<string> list = new List<string>(); |
| list.Add("Steam user"); |
| list.Add("Steam user"); |
| list.Add("PlayFab user"); |
| list.Add("PlayFab user"); |
| list.Add("Dedicated"); |
| list.Add("Dedicated"); |
| return "Known backends: " + string.Join(", ", list.Select((string s) => "\"" + s + "\"")); |
| return "Known backends: " + string.Join(", ", list.Select((string s) => "\"" + s + "\"")); |
| } |
| } |
| |
| |
| public void GetServers(List<ServerStatus> allServers) |
| public void GetServers(List<ServerStatus> allServers) |
| { |
| { |
| if (this.m_friendsFilter) |
| if (this.m_friendsFilter) |
| { |
| { |
| this.FilterServers(this.m_friendServers, allServers); |
| this.FilterServers(this.m_friendServers, allServers); |
| return; |
| return; |
| } |
| } |
| this.FilterServers(this.m_matchmakingServers, allServers); |
| this.FilterServers(this.m_matchmakingServers, allServers); |
| this.FilterServers(this.m_dedicatedServers, allServers); |
| this.FilterServers(this.m_dedicatedServers, allServers); |
| } |
| } |
| |
| |
| private void FilterServers(List<ServerStatus> input, List<ServerStatus> allServers) |
| private void FilterServers(List<ServerStatus> input, List<ServerStatus> allServers) |
| { |
| { |
| string text = this.m_nameFilter.ToLowerInvariant(); |
| string text = this.m_nameFilter.ToLowerInvariant(); |
| foreach (ServerStatus serverStatus in input) |
| foreach (ServerStatus serverStatus in input) |
| { |
| { |
| if (text.Length == 0 || serverStatus.m_joinData.m_serverName.ToLowerInvariant().Contains(text)) |
| if (text.Length == 0 || serverStatus.m_joinData.m_serverName.ToLowerInvariant().Contains(text)) |
| { |
| { |
| allServers.Add(serverStatus); |
| allServers.Add(serverStatus); |
| } |
| } |
| if (allServers.Count >= 200) |
| if (allServers.Count >= 200) |
| { |
| { |
| break; |
| break; |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| public bool CheckIfOnline(ServerJoinData dataToMatchAgainst, ref ServerStatus status) |
| public bool CheckIfOnline(ServerJoinData dataToMatchAgainst, ref ServerStatus status) |
| { |
| { |
| for (int i = 0; i < this.m_friendServers.Count; i++) |
| for (int i = 0; i < this.m_friendServers.Count; i++) |
| { |
| { |
| if (this.m_friendServers[i].m_joinData.Equals(dataToMatchAgainst)) |
| if (this.m_friendServers[i].m_joinData.Equals(dataToMatchAgainst)) |
| { |
| { |
| status = this.m_friendServers[i]; |
| status = this.m_friendServers[i]; |
| return true; |
| return true; |
| } |
| } |
| } |
| } |
| for (int j = 0; j < this.m_matchmakingServers.Count; j++) |
| for (int j = 0; j < this.m_matchmakingServers.Count; j++) |
| { |
| { |
| if (this.m_matchmakingServers[j].m_joinData.Equals(dataToMatchAgainst)) |
| if (this.m_matchmakingServers[j].m_joinData.Equals(dataToMatchAgainst)) |
| { |
| { |
| status = this.m_matchmakingServers[j]; |
| status = this.m_matchmakingServers[j]; |
| return true; |
| return true; |
| } |
| } |
| } |
| } |
| for (int k = 0; k < this.m_dedicatedServers.Count; k++) |
| for (int k = 0; k < this.m_dedicatedServers.Count; k++) |
| { |
| { |
| if (this.m_dedicatedServers[k].m_joinData.Equals(dataToMatchAgainst)) |
| if (this.m_dedicatedServers[k].m_joinData.Equals(dataToMatchAgainst)) |
| { |
| { |
| status = this.m_dedicatedServers[k]; |
| status = this.m_dedicatedServers[k]; |
| return true; |
| return true; |
| } |
| } |
| } |
| } |
| if (!this.IsRefreshing) |
| if (!this.IsRefreshing) |
| { |
| { |
| status = new ServerStatus(dataToMatchAgainst); |
| status = new ServerStatus(dataToMatchAgainst); |
| status.UpdateStatus(OnlineStatus.Offline, dataToMatchAgainst.m_serverName, 0U, default(GameVersion), new List<string>(), 0U, false, PrivilegeManager.Platform.Unknown, status.m_hostId, true); |
| status.UpdateStatus(OnlineStatus.Offline, dataToMatchAgainst.m_serverName, 0U, default(GameVersion), new List<string>(), 0U, false, PrivilegeManager.Platform.Unknown, status.m_hostId, true); |
| return true; |
| return true; |
| } |
| } |
| return false; |
| return false; |
| } |
| } |
| |
| |
| public bool GetJoinHost(out ServerJoinData joinData) |
| public bool GetJoinHost(out ServerJoinData joinData) |
| { |
| { |
| joinData = this.m_joinData; |
| joinData = this.m_joinData; |
| if (this.m_joinData == null) |
| if (this.m_joinData == null) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| if (!this.m_joinData.IsValid()) |
| if (!this.m_joinData.IsValid()) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| this.m_joinData = null; |
| this.m_joinData = null; |
| return true; |
| return true; |
| } |
| } |
| |
| |
| private void OnServerResponded(HServerListRequest request, int iServer) |
| private void OnServerResponded(HServerListRequest request, int iServer) |
| { |
| { |
| gameserveritem_t serverDetails = SteamMatchmakingServers.GetServerDetails(request, iServer); |
| gameserveritem_t serverDetails = SteamMatchmakingServers.GetServerDetails(request, iServer); |
| string serverName = serverDetails.GetServerName(); |
| string serverName = serverDetails.GetServerName(); |
| SteamNetworkingIPAddr steamNetworkingIPAddr = default(SteamNetworkingIPAddr); |
| SteamNetworkingIPAddr steamNetworkingIPAddr = default(SteamNetworkingIPAddr); |
| steamNetworkingIPAddr.SetIPv4(serverDetails.m_NetAdr.GetIP(), serverDetails.m_NetAdr.GetConnectionPort()); |
| steamNetworkingIPAddr.SetIPv4(serverDetails.m_NetAdr.GetIP(), serverDetails.m_NetAdr.GetConnectionPort()); |
| ServerStatus serverStatus = new ServerStatus(new ServerJoinDataDedicated(steamNetworkingIPAddr.GetIPv4(), steamNetworkingIPAddr.m_port)); |
| ServerStatus serverStatus = new ServerStatus(new ServerJoinDataDedicated(steamNetworkingIPAddr.GetIPv4(), steamNetworkingIPAddr.m_port)); |
| Dictionary<string, string> dictionary; |
| Dictionary<string, string> dictionary; |
| string text; |
| string text; |
| uint num; |
| uint num; |
| List<string> list; |
| List<string> list; |
| if (!StringUtils.TryDecodeStringAsIDictionary<Dictionary<string, string>>(serverDetails.GetGameTags(), out dictionary)) |
| if (!StringUtils.TryDecodeStringAsIDictionary<Dictionary<string, string>>(serverDetails.GetGameTags(), out dictionary)) |
| { |
| { |
| text = serverDetails.GetGameTags(); |
| text = serverDetails.GetGameTags(); |
| num = 0U; |
| num = 0U; |
| list = new List<string>(); |
| list = new List<string>(); |
| } |
| } |
| else |
| else |
| { |
| { |
| string text2; |
| string text2; |
| if ((!dictionary.TryGetValue("g", out text) && !dictionary.TryGetValue("gameversion", out text)) || (!dictionary.TryGetValue("n", out text2) && !dictionary.TryGetValue("networkversion", out text2)) || !uint.TryParse(text2, out num)) |
| if ((!dictionary.TryGetValue("g", out text) && !dictionary.TryGetValue("gameversion", out text)) || (!dictionary.TryGetValue("n", out text2) && !dictionary.TryGetValue("networkversion", out text2)) || !uint.TryParse(text2, out num)) |
| { |
| { |
| text = serverDetails.GetGameTags(); |
| text = serverDetails.GetGameTags(); |
| num = 0U; |
| num = 0U; |
| } |
| } |
| string text3; |
| string text3; |
| Dictionary<string, string> dictionary2; |
| Dictionary<string, string> dictionary2; |
| . | if (num != 23U || !dictionary.TryGetValue("m", out text3) || !StringUtils.TryDecodeStringAsIDictionary<Dictionary<string, string>>(text3, out dictionary2) || !ServerOptionsGUI.TryConvertCompactKVPToModifierKeys<List<string>>(dictionary2, out list)) |
| if (num != 27U || !dictionary.TryGetValue("m", out text3) || !StringUtils.TryDecodeStringAsIDictionary<Dictionary<string, string>>(text3, out dictionary2) || !ServerOptionsGUI.TryConvertCompactKVPToModifierKeys<List<string>>(dictionary2, out list)) |
| { |
| { |
| list = new List<string>(); |
| list = new List<string>(); |
| } |
| } |
| } |
| } |
| serverStatus.UpdateStatus(OnlineStatus.Online, serverName, (uint)serverDetails.m_nPlayers, GameVersion.ParseGameVersion(text), list, num, serverDetails.m_bPassword, PrivilegeManager.Platform.Steam, serverStatus.m_hostId, true); |
| serverStatus.UpdateStatus(OnlineStatus.Online, serverName, (uint)serverDetails.m_nPlayers, GameVersion.ParseGameVersion(text), list, num, serverDetails.m_bPassword, PrivilegeManager.Platform.Steam, serverStatus.m_hostId, true); |
| this.m_dedicatedServers.Add(serverStatus); |
| this.m_dedicatedServers.Add(serverStatus); |
| this.m_updateTriggerAccumulator++; |
| this.m_updateTriggerAccumulator++; |
| if (this.m_updateTriggerAccumulator > 100) |
| if (this.m_updateTriggerAccumulator > 100) |
| { |
| { |
| this.m_updateTriggerAccumulator = 0; |
| this.m_updateTriggerAccumulator = 0; |
| this.m_serverListRevision++; |
| this.m_serverListRevision++; |
| } |
| } |
| } |
| } |
| |
| |
| private void OnServerFailedToRespond(HServerListRequest request, int iServer) |
| private void OnServerFailedToRespond(HServerListRequest request, int iServer) |
| { |
| { |
| } |
| } |
| |
| |
| private void OnRefreshComplete(HServerListRequest request, EMatchMakingServerResponse response) |
| private void OnRefreshComplete(HServerListRequest request, EMatchMakingServerResponse response) |
| { |
| { |
| ZLog.Log("Refresh complete " + this.m_dedicatedServers.Count.ToString() + " " + response.ToString()); |
| ZLog.Log("Refresh complete " + this.m_dedicatedServers.Count.ToString() + " " + response.ToString()); |
| this.IsRefreshing = false; |
| this.IsRefreshing = false; |
| this.m_serverListRevision++; |
| this.m_serverListRevision++; |
| } |
| } |
| |
| |
| public void SetNameFilter(string filter) |
| public void SetNameFilter(string filter) |
| { |
| { |
| if (this.m_nameFilter == filter) |
| if (this.m_nameFilter == filter) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| this.m_nameFilter = filter; |
| this.m_nameFilter = filter; |
| this.m_serverListRevision++; |
| this.m_serverListRevision++; |
| } |
| } |
| |
| |
| public void SetFriendFilter(bool enabled) |
| public void SetFriendFilter(bool enabled) |
| { |
| { |
| if (this.m_friendsFilter == enabled) |
| if (this.m_friendsFilter == enabled) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| this.m_friendsFilter = enabled; |
| this.m_friendsFilter = enabled; |
| this.m_serverListRevision++; |
| this.m_serverListRevision++; |
| } |
| } |
| |
| |
| public int GetServerListRevision() |
| public int GetServerListRevision() |
| { |
| { |
| return this.m_serverListRevision; |
| return this.m_serverListRevision; |
| } |
| } |
| |
| |
| public int GetTotalNrOfServers() |
| public int GetTotalNrOfServers() |
| { |
| { |
| return this.m_matchmakingServers.Count + this.m_dedicatedServers.Count + this.m_friendServers.Count; |
| return this.m_matchmakingServers.Count + this.m_dedicatedServers.Count + this.m_friendServers.Count; |
| } |
| } |
| |
| |
| public bool IsRefreshing { get; private set; } |
| public bool IsRefreshing { get; private set; } |
| |
| |
| private static ZSteamMatchmaking m_instance; |
| private static ZSteamMatchmaking m_instance; |
| |
| |
| private const int maxServers = 200; |
| private const int maxServers = 200; |
| |
| |
| private List<ServerStatus> m_matchmakingServers = new List<ServerStatus>(); |
| private List<ServerStatus> m_matchmakingServers = new List<ServerStatus>(); |
| |
| |
| private List<ServerStatus> m_dedicatedServers = new List<ServerStatus>(); |
| private List<ServerStatus> m_dedicatedServers = new List<ServerStatus>(); |
| |
| |
| private List<ServerStatus> m_friendServers = new List<ServerStatus>(); |
| private List<ServerStatus> m_friendServers = new List<ServerStatus>(); |
| |
| |
| private int m_serverListRevision; |
| private int m_serverListRevision; |
| |
| |
| private int m_updateTriggerAccumulator; |
| private int m_updateTriggerAccumulator; |
| |
| |
| private CallResult<LobbyCreated_t> m_lobbyCreated; |
| private CallResult<LobbyCreated_t> m_lobbyCreated; |
| |
| |
| private CallResult<LobbyMatchList_t> m_lobbyMatchList; |
| private CallResult<LobbyMatchList_t> m_lobbyMatchList; |
| |
| |
| private CallResult<LobbyEnter_t> m_lobbyEntered; |
| private CallResult<LobbyEnter_t> m_lobbyEntered; |
| |
| |
| private Callback<GameServerChangeRequested_t> m_changeServer; |
| private Callback<GameServerChangeRequested_t> m_changeServer; |
| |
| |
| private Callback<GameLobbyJoinRequested_t> m_joinRequest; |
| private Callback<GameLobbyJoinRequested_t> m_joinRequest; |
| |
| |
| private Callback<LobbyDataUpdate_t> m_lobbyDataUpdate; |
| private Callback<LobbyDataUpdate_t> m_lobbyDataUpdate; |
| |
| |
| private Callback<GetAuthSessionTicketResponse_t> m_authSessionTicketResponse; |
| private Callback<GetAuthSessionTicketResponse_t> m_authSessionTicketResponse; |
| |
| |
| private Callback<SteamServerConnectFailure_t> m_steamServerConnectFailure; |
| private Callback<SteamServerConnectFailure_t> m_steamServerConnectFailure; |
| |
| |
| private Callback<SteamServersConnected_t> m_steamServersConnected; |
| private Callback<SteamServersConnected_t> m_steamServersConnected; |
| |
| |
| private Callback<SteamServersDisconnected_t> m_steamServersDisconnected; |
| private Callback<SteamServersDisconnected_t> m_steamServersDisconnected; |
| |
| |
| private ZSteamMatchmaking.ServerRegistered serverRegisteredCallback; |
| private ZSteamMatchmaking.ServerRegistered serverRegisteredCallback; |
| |
| |
| private CSteamID m_myLobby = CSteamID.Nil; |
| private CSteamID m_myLobby = CSteamID.Nil; |
| |
| |
| private CSteamID m_queuedJoinLobby = CSteamID.Nil; |
| private CSteamID m_queuedJoinLobby = CSteamID.Nil; |
| |
| |
| private ServerJoinData m_joinData; |
| private ServerJoinData m_joinData; |
| |
| |
| private List<KeyValuePair<CSteamID, string>> m_requestedFriendGames = new List<KeyValuePair<CSteamID, string>>(); |
| private List<KeyValuePair<CSteamID, string>> m_requestedFriendGames = new List<KeyValuePair<CSteamID, string>>(); |
| |
| |
| private ISteamMatchmakingServerListResponse m_steamServerCallbackHandler; |
| private ISteamMatchmakingServerListResponse m_steamServerCallbackHandler; |
| |
| |
| private ISteamMatchmakingPingResponse m_joinServerCallbackHandler; |
| private ISteamMatchmakingPingResponse m_joinServerCallbackHandler; |
| |
| |
| private HServerQuery m_joinQuery; |
| private HServerQuery m_joinQuery; |
| |
| |
| private HServerListRequest m_serverListRequest; |
| private HServerListRequest m_serverListRequest; |
| |
| |
| private bool m_haveListRequest; |
| private bool m_haveListRequest; |
| |
| |
| private bool m_refreshingDedicatedServers; |
| private bool m_refreshingDedicatedServers; |
| |
| |
| private bool m_refreshingPublicGames; |
| private bool m_refreshingPublicGames; |
| |
| |
| private string m_registerServerName = ""; |
| private string m_registerServerName = ""; |
| |
| |
| private bool m_registerPassword; |
| private bool m_registerPassword; |
| |
| |
| private GameVersion m_registerGameVerson; |
| private GameVersion m_registerGameVerson; |
| |
| |
| private uint m_registerNetworkVerson; |
| private uint m_registerNetworkVerson; |
| |
| |
| private List<string> m_registerModifiers = new List<string>(); |
| private List<string> m_registerModifiers = new List<string>(); |
| |
| |
| private string m_nameFilter = ""; |
| private string m_nameFilter = ""; |
| |
| |
| private bool m_friendsFilter = true; |
| private bool m_friendsFilter = true; |
| |
| |
| private HAuthTicket m_authTicket = HAuthTicket.Invalid; |
| private HAuthTicket m_authTicket = HAuthTicket.Invalid; |
| |
| |
| public delegate void ServerRegistered(bool success); |
| public delegate void ServerRegistered(bool success); |
| } |
| } |
| |
| |