Esempio n. 1
0
        private void ProcessLobbyCreated(LobbyCreated message)
        {
            var game = Startup.Config.Games.Where(g => g.Maps.Any(m => m.MapId == message.CustomMapName)).SingleOrDefault();

            if (game == null)
            {
                throw new Exception("Game with name not found: " + message.CustomMapName);
            }
            var channelId = Startup.Bot.Channels.Where(c => c.Value == game.Chat).SingleOrDefault().Key;
            var region    = Startup.Config.ServerRegions.Where(sr => sr.ServerId == message.SeverId).SingleOrDefault().LongName;
            var name      = game.Name;

            if (game.Maps.Count > 1)
            {
                name += " " + game.Maps.Where(m => m.MapId == message.CustomMapName).SingleOrDefault().Name;
            }
            Startup.Bot.DotaClient.QueueChatMessage(channelId, String.Format("New {0} lobby hosted in {1}", name, region), true);
            Startup.Bot.DotaClient.QueueLobbyShare(channelId, message.LobbyId, game.CustomGameMode, true);
            lock (LobbyStates) {
                var lobbyState = LobbyStates.Where(ls => ls.CustomMapName == message.CustomMapName && ls.ServerId == message.SeverId).FirstOrDefault();
                if (lobbyState != null)
                {
                    lobbyState.LobbyId = message.LobbyId;
                }
            }
        }
 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;
                }
            }
        }