protected virtual void OnLobbyCreated(Lobby newLobby) { if (LobbyCreated != null) { LobbyCreated.Invoke(this, new LobbyEventArgs() { Lobby = newLobby }); } }
/// <summary> /// Callback for when a steam lobby is created. Assign connection info and match info here for players to read when they connect. /// </summary> /// <param name="pCallback"></param> private void OnLobbyCreated(LobbyCreated_t pCallback) { // record which lobby we're in if (NetLogFilter.logInfo) { Debug.Log($"Lobby Created | ({Time.time})"); } if (pCallback.m_eResult == EResult.k_EResultOK) { // success if (NetLogFilter.logInfo) { Debug.Log($"LobbyID: {pCallback.m_ulSteamIDLobby}. ({Time.time})"); } LobbyCreated?.Invoke(new CSteamID(pCallback.m_ulSteamIDLobby)); } else { if (NetLogFilter.logInfo) { Debug.Log($"Failed to create lobby (lost connection to Steam back-end servers) ({Time.time})"); } } }
protected virtual void OnLobbyCreated(object source, EventArgs e) { LobbyCreated?.Invoke(source, e); }
private static void Responses() { while (ResponseThreadRunning) { // listens to responses from the middle man server string response = GetResponse(); if (response != "") { string[] sections = response.Split('|'); string responseType = sections[0]; string parameters = sections[1].Replace("\r", "").Replace("\n", ""); Console.WriteLine(responseType + " | " + parameters); switch (responseType) { case "CONNECTED": User.Name = parameters; ConnectedSuccess?.Invoke(); break; case "PING": SendMessage("PONG|"); break; case "LOBBY_LIST": string[] lobbies = parameters.Split(','); List <LobbyListItem> lobbyList = new List <LobbyListItem>(); foreach (string lobby in lobbies) { string[] info = lobby.Split('-'); if (int.TryParse(info[0], out int id) && int.TryParse(info[2], out int status) && int.TryParse(info[3], out int player_count)) { lobbyList.Add(new LobbyListItem(id, info[1], (LobbyStatus)status, player_count)); } } NewLobbyList?.Invoke(lobbyList); break; case "HOSTING": LobbyCreated?.Invoke(); break; case "PUNCH-HOST": Console.WriteLine("HOST PUNCHING"); Socket connectionToC = PerformPunchThrough(sections[1].Split(':')); if (connectionToC != null) { SendMessage("PLAYER_CONNECT_SUCCESS|"); UserConnected?.Invoke(connectionToC); } else { SendMessage("PLAYER_CONNECT_FAIL|"); } break; case "PUNCH-CLIENT": Console.WriteLine("CLIENT PUNCHING"); Socket connectionToH = PerformPunchThrough(sections[1].Split(':')); if (connectionToH != null) { JoinLobbySuccess?.Invoke(connectionToH); } else { JoinLobbyFailure.Invoke(); } break; } } else { // AttemptReconnect(); break; } } }