Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public override void Awake()
- {
- base.Awake();
- lobbyIDs = new List<CSteamID>();
- myListOfLobbies = new List<ButtonLobby>();
- Callback_lobbyCreated = Callback<LobbyCreated_t>.Create(OnLobbyCreate);
- Callback_lobbyList = Callback<LobbyMatchList_t>.Create(OnLobbyList);
- Call_matchList_t = CallResult<LobbyMatchList_t>.Create(OnGetLobbiesList);
- Callback_lobbyEnter = Callback<LobbyEnter_t>.Create(OnLobbyEnter);
- Callback_lobbyInfo = Callback<LobbyDataUpdate_t>.Create(OnGetLobbyInfo);
- stuffToDestroy = new List<GameObject>();
- gameObject.AddComponent<NetworkMatch>();
- }
- /// <summary>
- /// This is only for reducing the number of words every time you would use NetworkController.singleton
- /// </summary>
- public static NetworkController instance
- {
- get { return ((NetworkController)NetworkController.singleton); }
- }
- public void CreateGame(string name, uint maxPlayers, string password, int mapId)
- {
- currentMapId = mapId;
- StartMatchMaker();
- StartHostAll(name, maxPlayers, true, password, 0, 0, myPort);
- }
- public override void OnMatchCreate(bool success, string extendedInfo, MatchInfo matchInfo)
- {
- LogGenerator.GenerateLog("Network Controller", "Match is created, creating lobby now");
- if (usingSteamMatchmaking)
- {
- SteamMatchmaking.CreateLobby(ELobbyType.k_ELobbyTypePublic, (int)instance.matchSize);
- }
- base.OnMatchCreate(success, extendedInfo, matchInfo);
- LogGenerator.GenerateLog("Network Controller", "Lobby Successfully created");
- }
- public void OnLobbyCreate(LobbyCreated_t result)
- {
- if(result.m_eResult == EResult.k_EResultOK)
- {
- __externalIp = instance.hostExternalIP;
- __externalIPV6 = instance.hostExternalIPv6;
- __internalIp = instance.hostInternalIP;
- __internalIPV6 = instance.hostInternalIP;
- LogGenerator.GenerateLog("NetworkController", "Lobby created sucessfully. Setting Lobby data");
- myLobby = (CSteamID)result.m_ulSteamIDLobby;
- LogGenerator.GenerateLog("Network Controller", "Lobby identificator is " + result.m_ulSteamIDLobby.ToString());
- SteamMatchmaking.SetLobbyData((CSteamID)result.m_ulSteamIDLobby, "name", instance.matchName);
- SteamMatchmaking.SetLobbyData((CSteamID)result.m_ulSteamIDLobby, "publicIP", instance.hostExternalIP);
- SteamMatchmaking.SetLobbyData((CSteamID)result.m_ulSteamIDLobby, "publicIPv6", instance.hostExternalIPv6);
- SteamMatchmaking.SetLobbyData((CSteamID)result.m_ulSteamIDLobby, "internalIP", instance.hostInternalIP);
- SteamMatchmaking.SetLobbyData((CSteamID)result.m_ulSteamIDLobby, "internalIPV6", instance.hostInternalIPv6);
- SteamMatchmaking.SetLobbyData((CSteamID)result.m_ulSteamIDLobby, "map", instance.listOfMaps[currentMapId]);
- SteamMatchmaking.SetLobbyData((CSteamID)result.m_ulSteamIDLobby, "matchID", instance.matchID.ToString());
- SteamMatchmaking.SetLobbyData((CSteamID)result.m_ulSteamIDLobby, "guid", GetComponent<NATHelper>().guid.ToString());
- LogGenerator.GenerateLog("Network Controller", "Lobby data sucessfully stored.");
- }
- }
- void OnLobbyList(LobbyMatchList_t result)
- {
- }
- public void GetListOfHostsWithoutSteam(int page, int pagesize)
- {
- LogGenerator.GenerateLog("NetworkController", "Getting list of matches without steam");
- listGet = false;
- NetworkController.instance.matchMaker.ListMatches(page, pagesize, "", false, 0, 0, OnMatchList);
- LogGenerator.GenerateLog("NetworkController", "Ending Call List host without steam");
- }
- public void GetListOfLobbies(int page, int pagesize)
- {
- //if(callForListLobbies != null)
- LogGenerator.GenerateLog("Network Controller", "Getting List of Steam Lobbies");
- listGet = false;
- SteamMatchmaking.AddRequestLobbyListResultCountFilter(pagesize);
- callForListLobbies = SteamMatchmaking.RequestLobbyList();
- Call_matchList_t.Set(callForListLobbies);
- }
- public void OnGetLobbyInfo(LobbyDataUpdate_t result)
- {
- if (((int)result.m_bSuccess)>0)
- LogGenerator.GenerateLog("Network Controller", "Lobby " + result.m_ulSteamIDLobby + " successfully updated");
- }
- public override void OnStartHost()
- {
- LogGenerator.GenerateLog("Network Controller", " I started a host, setting controller flags ");
- isHost = true;
- if (usingSteamMatchmaking)
- {
- SteamMatchmaking.CreateLobby(ELobbyType.k_ELobbyTypePublic, (int)instance.matchSize);
- }
- base.OnStartHost();
- ChangeScene(currentMapId);
- }
- public override void OnStartServer()
- {
- isServer = true;
- if (usingSteamMatchmaking)
- {
- SteamMatchmaking.CreateLobby(ELobbyType.k_ELobbyTypePublic, (int)instance.matchSize);
- }
- base.OnStartServer();
- ChangeScene(currentMapId);
- }
- public void JoinGame(int serverIndex, string password)
- {
- if(!usingSteamMatchmaking)
- {
- StartClientAll(myListOfLobbies[serverIndex].myMatch, null, password);
- }
- else
- {
- SteamAPICall_t tryLobby = SteamMatchmaking.JoinLobby(lobbyIDs[serverIndex]);
- }
- }
- public override void OnStartClient(NetworkClient client)
- {
- base.OnStartClient(client);
- }
- void OnGetLobbiesList(LobbyMatchList_t result, bool failure)
- {
- LogGenerator.GenerateLog("Network Controller", "Lobby list returned");
- LogGenerator.GenerateLog("Network Controller", "Total of " + result.m_nLobbiesMatching.ToString() + " lobby(s)");
- //LogGenerator.GenerateLog("NetworkController", "found " + result.m_nLobbiesMatching + " Lobbies");
- for(int i = 0; i < result.m_nLobbiesMatching; i++)
- {
- CSteamID tmp = SteamMatchmaking.GetLobbyByIndex(i);
- lobbyIDs.Add(tmp);
- LogGenerator.GenerateLog("NetworkController", "Lobby " + tmp.ToString() + " added to LobbyIDs");
- ButtonLobby bl = new ButtonLobby();
- bl.lobbySelectionIndex = i;
- bl.steamLobby = tmp;
- bl.lobbyName = SteamMatchmaking.GetLobbyData(tmp, "name");
- bl.mapName = SteamMatchmaking.GetLobbyData(tmp, "map");
- bl.gameDescription = SteamMatchmaking.GetLobbyData(tmp, "Description");
- bl.currentNumberOfPlayers = SteamMatchmaking.GetNumLobbyMembers(tmp);
- bl.maxNumberOfPlayers = SteamMatchmaking.GetLobbyMemberLimit(tmp);
- LogGenerator.GenerateLog("Network Controller", "button with index " + i + " sucessfully saved");
- }
- listGet = true;
- }
- public void OnLobbyEnter(LobbyEnter_t result)
- {
- LogGenerator.GenerateLog("Network Controller", "Lobby entered");
- SteamMatchmaking.GetLobbyData((CSteamID)result.m_ulSteamIDLobby, "name");
- string _publicIP = SteamMatchmaking.GetLobbyData((CSteamID)result.m_ulSteamIDLobby, "publicIP");
- string _pubIPV6 = SteamMatchmaking.GetLobbyData((CSteamID)result.m_ulSteamIDLobby, "publicIPv6");
- string _internalIP = SteamMatchmaking.GetLobbyData((CSteamID)result.m_ulSteamIDLobby, "internalIP");
- string _internaIPV6 = SteamMatchmaking.GetLobbyData((CSteamID)result.m_ulSteamIDLobby, "internalIPV6");
- string _map = SteamMatchmaking.GetLobbyData((CSteamID)result.m_ulSteamIDLobby, "map");
- //ulong tmp = ulong.Parse(SteamMatchmaking.GetLobbyData((CSteamID)result.m_ulSteamIDLobby, "matchID"));
- ulong guid = ulong.Parse(SteamMatchmaking.GetLobbyData((CSteamID)result.m_ulSteamIDLobby, "guid"));
- LogGenerator.GenerateLog("Network Controller", "Starting Client");
- StartClientAll(_publicIP, _internalIP, myPort, guid, NetworkID.Invalid , _pubIPV6, _internaIPV6, OnMatchJoined, myPassword);
- }
- public Soldier[] soldiersM;
- public Soldier[] soldiersF;
- public override void OnMatchJoined(bool success, string extendedInfo, MatchInfo info)
- {
- isClient = true;
- base.OnMatchJoined(success, extendedInfo, info);
- }
- public override void OnMatchList(bool success, string extendedInfo, List<MatchInfoSnapshot> matchList)
- {
- LogGenerator.GenerateLog("Network Controller", "Listing matchs without Steamworks ");
- if(success)
- {
- myListOfLobbies.Clear();
- LogGenerator.GenerateLog("Network Controller", "List of Matchs cleared");
- ButtonLobby bl;
- for(int i = 0; i < matchList.Count; i++)
- {
- MatchInfoSnapshot mis = matchList[i];
- bl = new ButtonLobby();
- bl.myMatch = mis;
- bl.lobbyName = mis.name;
- bl.currentNumberOfPlayers = mis.currentSize;
- bl.maxNumberOfPlayers = mis.maxSize;
- bl.myPing = -1;
- bl.mapId = mis.averageEloScore;
- bl.lobbySelectionIndex = i;
- myListOfLobbies.Add(bl);
- LogGenerator.GenerateLog("Network Controller", "Lobby Generated");
- }
- }
- listGet = true;
- base.OnMatchList(success, extendedInfo, matchList);
- }
- public void ChangeScene(int id)
- {
- if (isServer || isHost)
- {
- if (id >= 0 && id < listOfMaps.Length)
- {
- while (stuffToDestroy.Count > 0)
- {
- Destroy(stuffToDestroy[0]);
- }
- instance.ServerChangeScene(listOfMaps[id]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement