Esempio n. 1
0
        private static IEnumerator SendSceneLoad(int connectionId)
        {
            // wait until we've received the loadout
            while (!NetworkMatch.m_player_loadout_data.ContainsKey(connectionId))
            {
                if (!NetworkMatch.m_players.ContainsKey(connectionId)) // disconnected?
                {
                    yield break;
                }
                yield return(null);
            }

            StringMessage levelNameMsg = new StringMessage(MPJoinInProgress.NetworkMatchLevelName());

            NetworkServer.SendToClient(connectionId, CustomMsgType.SceneLoad, levelNameMsg);
            Debug.Log("JIP: sending scene load " + levelNameMsg.value);

            if (NetworkMatch.GetMatchState() == MatchState.LOBBY_LOADING_SCENE)
            {
                yield break;
            }

            StringMessage sceneNameMsg = new StringMessage(GameplayManager.m_level_info.SceneName);

            NetworkServer.SendToClient(connectionId, CustomMsgType.SceneLoaded, sceneNameMsg);
            Debug.Log("JIP: sending scene loaded " + sceneNameMsg.value);
        }
        public static IEnumerator DelayedDisconnect(int connection_id, bool banned)
        {
            if (connection_id < NetworkServer.connections.Count && NetworkServer.connections[connection_id] != null)
            {
                NetworkConnection conn = NetworkServer.connections[connection_id];
                if (NetworkMatch.GetMatchState() >= MatchState.PREGAME)
                {
                    // Sending this command first prevents the client to load the scene
                    // and getting into some inconsistend state
                    NetworkServer.SendToClient(connection_id, CustomMsgType.MatchEnd, new IntegerMessage(0));
                    yield return(new WaitForSecondsRealtime(0.5f));
                }
                // nicely tell the client to F**K OFF :)
                NetworkServer.SendToClient(connection_id, CustomMsgType.UnsupportedMatch, new StringMessage(String.Format("You {0} from this server", (banned)?"are BANNED":"were KICKED")));
                yield return(new WaitForSecondsRealtime(0.5f));

                // Fake client's OnDisconnect message
                NetworkMessage msg = new NetworkMessage();
                msg.conn    = conn;
                msg.msgType = 33; // Disconnect
                _Server_OnDisconnect_Method.Invoke(null, new object[] { msg });
                // get rid of the client
                conn.Disconnect();
            }
        }
Esempio n. 3
0
 private static void Postfix(NetworkMessage msg)
 {
     if (NetworkMatch.GetMatchState() == MatchState.PLAYING)
     {
         GameManager.m_gm.StartCoroutine(MatchStart(msg.conn.connectionId));
     }
 }
Esempio n. 4
0
        private static void Postfix(NetworkMessage msg)
        {
            var connId = msg.conn.connectionId;

            if (connId == 0) // ignore local connection
            {
                return;
            }
            if (!MPTweaks.ClientInfos.TryGetValue(connId, out var clientInfo))
            {
                clientInfo = MPTweaks.ClientCapabilitiesSet(connId, new Dictionary <string, string>());
            }
            Debug.Log("MPTweaks: conn " + connId + " OnLoadoutDataMessage clientInfo is now " + clientInfo.Capabilities.Join());
            if (!MPTweaks.ClientHasMod(connId) && MPTweaks.MatchNeedsMod())
            {
                //LobbyChatMessage chatMsg = new LobbyChatMessage(connId, "SERVER", MpTeam.ANARCHY, "You need OLMOD to join this match", false);
                //NetworkServer.SendToClient(connId, CustomMsgType.LobbyChatToClient, chatMsg);
                NetworkServer.SendToClient(connId, 86, new StringMessage("This match requires OLMod to play."));
                GameManager.m_gm.StartCoroutine(DisconnectCoroutine(connId));
            }
            if ((NetworkMatch.GetMatchState() != MatchState.LOBBY && NetworkMatch.GetMatchState() != MatchState.LOBBY_LOAD_COUNTDOWN) && !ClientLoadoutValid(connId))
            {
                NetworkServer.SendToClient(connId, 86, new StringMessage("This match has disabled modifiers.  Please disable these modifiers and try again: " + MPModifiers.GetDisabledModifiers()));
                GameManager.m_gm.StartCoroutine(DisconnectCoroutine(connId));
            }
            if (!clientInfo.Capabilities.ContainsKey("ClassicWeaponSpawns") && (MPClassic.matchEnabled || MPModPrivateData.ClassicSpawnsEnabled))
            {
                NetworkServer.SendToClient(connId, 86, new StringMessage("This match has classic weapon spawns and requires OLMod 0.3.6 or greater."));
                GameManager.m_gm.StartCoroutine(DisconnectCoroutine(connId));
            }
            if (clientInfo.Capabilities.ContainsKey("ModPrivateData"))
            {
                MPModPrivateDataTransfer.SendTo(connId);
            }
        }
Esempio n. 5
0
 public static void OnNewPlayerSnapshotToClient(NetworkMessage msg)
 {
     if (NetworkMatch.GetMatchState() == MatchState.PREGAME || NetworkMatch.InGameplay())
     {
         PlayerSnapshotToClientMessage item = msg.ReadMessage <NewPlayerSnapshotToClientMessage>().ToPlayerSnapshotToClientMessage();
         Client.m_PendingPlayerSnapshotMessages.Enqueue(item);
     }
 }
Esempio n. 6
0
        // when using the new protocol, this object replaces
        // Client.m_PendingPlayerSnapshotMessages
        //public static Queue<NewPlayerSnapshotToClientMessage> m_PendingPlayerSnapshotMessages = new Queue<NewPlayerSnapshotToClientMessage>();

        public static void OnNewPlayerSnapshotToClient(NetworkMessage msg)
        {
            if (NetworkMatch.GetMatchState() == MatchState.PREGAME || NetworkMatch.InGameplay())
            {
                NewPlayerSnapshotToClientMessage item = msg.ReadMessage <NewPlayerSnapshotToClientMessage>();
                MPClientShipReckoning.AddNewPlayerSnapshot(item);
            }
        }
Esempio n. 7
0
        private static void Postfix(NetworkMessage msg)
        {
            MatchState match_state = NetworkMatch.GetMatchState();

            if (match_state != MatchState.LOBBY && match_state != MatchState.LOBBY_LOAD_COUNTDOWN)
            {
                GameManager.m_gm.StartCoroutine(SendSceneLoad(msg.conn.connectionId));
            }
        }
 private static void DrawTurnspeedModeOption(UIElement uie, ref Vector2 position)
 {
     if (!server_support && !GameplayManager.IsMultiplayerActive && NetworkMatch.GetMatchState() != MatchState.LOBBY)
     {
         server_support = true;
         Debug.Log("JoystickRamping.server_support didnt reset properly");
     }
     position.y += 55f;
     uie.SelectAndDrawStringOptionItem(Loc.LS("MAX TURN RAMP MODE"), position, 0, alt_turn_ramp_mode ? "LINEAR" : "DEFAULT", "LINEAR ADDS THE MAX TURN RAMPING SPEED LINEARLY ALONG THE INPUT [KB/JOYSTICK ONLY]", 1.5f, !server_support);
 }
        // Send a chat message
        // Set connection_id to the ID of a specific client, or to -1 to send to all
        // clients except except_connection_id (if that is >= 0)
        // if onlyAuth is true, onlsy sent to clients which are authenticated for
        // If unblockedOnly is true, only send to clients which are not BlockChat-BANNED
        // chat commands
        public static bool SendTo(string msg, int connection_id = -1, int except_connection_id = -1, bool authOnly = false, bool unblockedOnly = false, string sender_name = "Server", MpTeam team = MpTeam.TEAM0, bool isTeamMessage = false, int sender_connection_id = -1)
        {
            MatchState s = NetworkMatch.GetMatchState();

            if (s == MatchState.NONE || s == MatchState.LOBBY_LOADING_SCENE)
            {
                Debug.LogFormat("MPChatTools SendTo() called during match state {0}, ignored", s);
                return(false);
            }
            bool inLobby = (s == MatchState.LOBBY || s == MatchState.LOBBY_LOAD_COUNTDOWN);

            return(SendTo(inLobby, msg, connection_id, except_connection_id, authOnly, unblockedOnly, sender_name, team, isTeamMessage, sender_connection_id));
        }
Esempio n. 10
0
 public static void Set(Dictionary <string, string> newSettings)
 {
     settings.Clear();
     foreach (var x in newSettings)
     {
         settings.Add(x.Key, x.Value);
     }
     //Debug.Log("MPTweaks.Set " + (Overload.NetworkManager.IsServer() ? "server" : "conn " + NetworkMatch.m_my_lobby_id) + " new " + newSettings.Join() + " settings " + settings.Join());
     if (NetworkMatch.GetMatchState() == MatchState.PLAYING)
     {
         Apply();
     }
 }
Esempio n. 11
0
 public static bool Prefix(NetworkMessage msg)
 {
     if (NetworkMatch.GetMatchState() == MatchState.PREGAME || NetworkMatch.InGameplay())
     {
         PlayerSnapshotToClientMessage    item    = msg.ReadMessage <PlayerSnapshotToClientMessage>();
         NewPlayerSnapshotToClientMessage newItem = new NewPlayerSnapshotToClientMessage {
             m_num_snapshots    = item.m_num_snapshots,
             m_server_timestamp = 0, // Unused.
             m_snapshots        = item.m_snapshots.Select(m => NewPlayerSnapshot.FromOldSnapshot(m)).ToArray()
         };
         MPClientShipReckoning.AddNewPlayerSnapshot(newItem, true);
     }
     return(false);
 }
        private static void Postfix(NetworkMessage msg)
        {
            MatchState match_state = NetworkMatch.GetMatchState();

            if (match_state != MatchState.LOBBY && match_state != MatchState.LOBBY_LOAD_COUNTDOWN)
            {
                GameManager.m_gm.StartCoroutine(SendSceneLoad(msg.conn.connectionId));
            }
            else
            {
                string level       = MPJoinInProgress.NetworkMatchLevelName();
                bool   customLevel = (level != null)? level.Contains(':') : false;
                GameManager.m_gm.StartCoroutine(InformClientAboutOlmod(msg.conn.connectionId, customLevel, 0));
            }
        }
        public static void Postfix()
        {
            MatchState state = NetworkMatch.GetMatchState();

            if (state != MatchState.LOBBY && state != MatchState.LOBBY_LOADING_SCENE && state != MatchState.LOBBY_LOAD_COUNTDOWN)
            {
                return;
            }

            var obj = ServerStatLog.GetGameData();

            obj["name"] = "Stats";
            obj["type"] = "LobbyStatus";

            ServerStatLog.TrackerPostStats(obj);
        }
Esempio n. 14
0
        public static void Disconnected(string name)
        {
            if (NetworkMatch.m_postgame || NetworkMatch.GetMatchState() == MatchState.NONE)
            {
                return;
            }

            var obj = JObject.FromObject(new
            {
                name   = "Stats",
                type   = "Disconnect",
                time   = NetworkMatch.m_match_elapsed_seconds,
                player = name
            });

            TrackerPostStats(obj);
        }
Esempio n. 15
0
        private static void Postfix(NetworkMessage msg)
        {
            int connectionId = msg.conn.connectionId;

            if (!MPTweaks.ClientHasMod(connectionId) && MPTweaks.MatchNeedsMod())
            {
                return;
            }

            if (NetworkMatch.GetMatchState() == MatchState.PLAYING)
            {
                GameManager.m_gm.StartCoroutine(MatchStart(connectionId));
            }
            else if (NetworkMatch.GetMatchState() == MatchState.PREGAME && NetworkMatch.m_pregame_countdown_active)
            {
                SendPreGame(connectionId, NetworkMatch.m_pregame_countdown_seconds_left);
            }
        }
Esempio n. 16
0
        private static void Postfix(NetworkMessage msg)
        {
            var connId = msg.conn.connectionId;

            if (connId == 0) // ignore local connection
            {
                return;
            }
            if (!MPTweaks.ClientInfos.TryGetValue(connId, out var clientInfo))
            {
                clientInfo = MPTweaks.ClientCapabilitiesSet(connId, new Dictionary <string, string>());
            }

            /*
             * if (!clientInfo.SupportsTweaks.Contains("proj") && !MPTweaks.IncompatibleMatchReported)
             * {
             *  MPTweaks.IncompatibleMatchReported = true;
             *  string name = NetworkMatch.m_players.TryGetValue(connId, out var playerData) ? playerData.m_name : connId.ToString();
             *  var text = "DISABLED HUNTER SPEED CHANGE! OLD OLMOD: " + name;
             *  Debug.LogFormat("MPTweaks: IncompatibleMatchReported {0}", text);
             *  JIPClientHandlers.SendAddMpStatus(text);
             * }
             */
            Debug.Log("MPTweaks: conn " + connId + " OnLoadoutDataMessage clientInfo is now " + clientInfo.Capabilities.Join());
            if (!MPTweaks.ClientHasMod(connId) && MPTweaks.MatchNeedsMod())
            {
                //LobbyChatMessage chatMsg = new LobbyChatMessage(connId, "SERVER", MpTeam.ANARCHY, "You need OLMOD to join this match", false);
                //NetworkServer.SendToClient(connId, CustomMsgType.LobbyChatToClient, chatMsg);
                NetworkServer.SendToClient(connId, 86, new StringMessage("You need OLMOD to join this match."));
                GameManager.m_gm.StartCoroutine(DisconnectCoroutine(connId));
            }
            if ((NetworkMatch.GetMatchState() != MatchState.LOBBY && NetworkMatch.GetMatchState() != MatchState.LOBBY_LOAD_COUNTDOWN) && !ClientLoadoutValid(connId))
            {
                NetworkServer.SendToClient(connId, 86, new StringMessage("This match has disabled modifiers: " + MPModifiers.GetDisabledModifiers()));
                GameManager.m_gm.StartCoroutine(DisconnectCoroutine(connId));
            }
            if (clientInfo.Capabilities.ContainsKey("ModPrivateData"))
            {
                MPModPrivateDataTransfer.SendTo(connId);
            }
        }
        private static IEnumerator SendSceneLoad(int connectionId)
        {
            // wait until we've received the loadout
            while (!NetworkMatch.m_player_loadout_data.ContainsKey(connectionId))
            {
                if (!NetworkMatch.m_players.ContainsKey(connectionId)) // disconnected?
                {
                    yield break;
                }
                yield return(null);
            }
            string level       = MPJoinInProgress.NetworkMatchLevelName();
            bool   customLevel = (level != null)? level.Contains(':') : false;

            if (customLevel && !MPTweaks.ClientHasMod(connectionId))
            {
                // client seems not to have olmod, warn it
                yield return(GameManager.m_gm.StartCoroutine(InformClientAboutOlmod(connectionId, customLevel, 8)));

                if (!NetworkMatch.m_players.ContainsKey(connectionId)) // disconnected?
                {
                    yield break;
                }
            }

            StringMessage levelNameMsg = new StringMessage(level);

            NetworkServer.SendToClient(connectionId, CustomMsgType.SceneLoad, levelNameMsg);
            Debug.Log("JIP: sending scene load " + levelNameMsg.value);

            if (NetworkMatch.GetMatchState() == MatchState.LOBBY_LOADING_SCENE)
            {
                yield break;
            }

            StringMessage sceneNameMsg = new StringMessage(GameplayManager.m_level_info.SceneName);

            NetworkServer.SendToClient(connectionId, CustomMsgType.SceneLoaded, sceneNameMsg);
            Debug.Log("JIP: sending scene loaded " + sceneNameMsg.value);
        }
        // Kicks all players who are BANNED (Lobby and otherwise)
        public static void KickBannedPlayers()
        {
            if (GetList(MPBanMode.Ban).Count < 1)
            {
                // no bans active
                return;
            }
            MatchState s       = NetworkMatch.GetMatchState();
            bool       inLobby = (s == MatchState.LOBBY || s == MatchState.LOBBY_LOAD_COUNTDOWN);

            if (inLobby)
            {
                // Kick Lobby Players
                foreach (KeyValuePair <int, PlayerLobbyData> p in NetworkMatch.m_players)
                {
                    if (p.Value != null)
                    {
                        MPBanEntry candidate = new MPBanEntry(p.Value);
                        if (IsBanned(candidate, MPBanMode.Ban))
                        {
                            KickPlayer(p.Value, true);
                        }
                    }
                }
            }
            else
            {
                foreach (var p in Overload.NetworkManager.m_Players)
                {
                    MPBanEntry candidate = new MPBanEntry(p);
                    if (IsBanned(candidate, MPBanMode.Ban))
                    {
                        KickPlayer(p, true);
                    }
                }
            }
        }
Esempio n. 19
0
        private static IEnumerator MatchStart(int connectionId)
        {
            var newPlayer = Server.FindPlayerByConnectionId(connectionId);

            float pregameWait = 3f;

            if (!newPlayer.m_mp_name.StartsWith("OBSERVER"))
            {
                foreach (Player player in Overload.NetworkManager.m_Players)
                {
                    if (MPTweaks.ClientHasTweak(player.connectionToClient.connectionId, "jip"))
                    {
                        NetworkServer.SendToClient(player.connectionToClient.connectionId, MessageTypes.MsgJIPJustJoined, new JIPJustJoinedMessage {
                            playerId = newPlayer.netId, ready = false
                        });
                    }
                }
                MPJoinInProgress.SetReady(newPlayer, false);
            }

            pregameWait = SendPreGame(connectionId, pregameWait);
            yield return(new WaitForSeconds(pregameWait));

            Server.SendLoadoutDataToClients();

            if (newPlayer.m_mp_name.StartsWith("OBSERVER"))
            {
                Debug.LogFormat("Enabling spectator for {0}", newPlayer.m_mp_name);
                newPlayer.Networkm_spectator = true;
                Debug.LogFormat("Enabled spectator for {0}", newPlayer.m_mp_name);

                yield return(null); // make sure spectator change is received before sending MatchStart
            }
            else
            {
                foreach (Player player in Overload.NetworkManager.m_Players)
                {
                    if (MPTweaks.ClientHasTweak(player.connectionToClient.connectionId, "jip"))
                    {
                        NetworkServer.SendToClient(player.connectionToClient.connectionId, MessageTypes.MsgJIPJustJoined, new JIPJustJoinedMessage {
                            playerId = newPlayer.netId, ready = true
                        });
                    }
                }
                MPJoinInProgress.SetReady(newPlayer, true);
            }

            if (NetworkMatch.GetMatchState() != MatchState.PLAYING)
            {
                yield break;
            }

            IntegerMessage modeMsg = new IntegerMessage((int)NetworkMatch.GetMode());

            NetworkServer.SendToClient(connectionId, CustomMsgType.MatchStart, modeMsg);
            SendMatchState(connectionId);

            NetworkSpawnPlayer.Respawn(newPlayer.c_player_ship);
            MPTweaks.Send(connectionId);
            //if (!newPlayer.m_spectator && RearView.MPNetworkMatchEnabled)
            //    newPlayer.CallTargetAddHUDMessage(newPlayer.connectionToClient, "REARVIEW ENABLED", -1, true);
            CTF.SendJoinUpdate(newPlayer);
            Race.SendJoinUpdate(newPlayer);
            foreach (Player player in Overload.NetworkManager.m_Players)
            {
                if (player.connectionToClient.connectionId == connectionId)
                {
                    continue;
                }
                // Resend mode for existing player to move h2h -> anarchy
                NetworkServer.SendToClient(player.connectionToClient.connectionId, CustomMsgType.MatchStart, modeMsg);

                if (!newPlayer.m_spectator)
                {
                    player.CallTargetAddHUDMessage(player.connectionToClient, String.Format(Loc.LS("{0} JOINED MATCH"), newPlayer.m_mp_name), -1, true);
                }

                //Debug.Log("JIP: spawning on new client net " + player.netId + " lobby " + player.connectionToClient.connectionId);
                NetworkServer.SendToClient(connectionId, CustomMsgType.Respawn, new RespawnMessage
                {
                    m_net_id     = player.netId,
                    lobby_id     = player.connectionToClient.connectionId,
                    m_pos        = player.transform.position,
                    m_rotation   = player.transform.rotation,
                    use_loadout1 = player.m_use_loadout1
                });
            }
            ServerStatLog.Connected(newPlayer.m_mp_name);
        }
Esempio n. 20
0
 public static bool MatchHasStartedMod(bool m_match_has_started)
 {
     return(m_match_has_started && (!NetworkMatchEnabled || (int)NetworkMatch.GetMatchState() >= (int)MatchState.POSTGAME));
 }
        private static IEnumerator MatchStart(int connectionId)
        {
            var        newPlayer      = Server.FindPlayerByConnectionId(connectionId);
            MPBanEntry newPlayerEntry = new MPBanEntry(newPlayer);

            // prevent banned players from JIP into our match
            // there is already a delayed Disconnect going on, just
            // prevent this player from entering the JIP code
            if (MPBanPlayers.IsBanned(newPlayerEntry))
            {
                yield break;
            }

            float pregameWait = 3f;

            if (!newPlayer.m_mp_name.StartsWith("OBSERVER"))
            {
                foreach (Player player in Overload.NetworkManager.m_Players)
                {
                    if (MPTweaks.ClientHasTweak(player.connectionToClient.connectionId, "jip"))
                    {
                        NetworkServer.SendToClient(player.connectionToClient.connectionId, MessageTypes.MsgJIPJustJoined, new JIPJustJoinedMessage {
                            playerId = newPlayer.netId, ready = false
                        });
                    }
                }
                MPJoinInProgress.SetReady(newPlayer, false, true); // special case: do not disable the player completely, as this would prevent this player to be sent to new clients joining before we finally switch to ready
            }

            pregameWait = SendPreGame(connectionId, pregameWait);
            yield return(new WaitForSeconds(pregameWait));

            Server.SendLoadoutDataToClients();

            if (newPlayer.m_mp_name.StartsWith("OBSERVER"))
            {
                Debug.LogFormat("Enabling spectator for {0}", newPlayer.m_mp_name);
                newPlayer.Networkm_spectator = true;
                Debug.LogFormat("Enabled spectator for {0}", newPlayer.m_mp_name);

                yield return(null); // make sure spectator change is received before sending MatchStart
            }
            else
            {
                foreach (Player player in Overload.NetworkManager.m_Players)
                {
                    if (MPTweaks.ClientHasTweak(player.connectionToClient.connectionId, "jip"))
                    {
                        NetworkServer.SendToClient(player.connectionToClient.connectionId, MessageTypes.MsgJIPJustJoined, new JIPJustJoinedMessage {
                            playerId = newPlayer.netId, ready = true
                        });
                    }
                }
                MPJoinInProgress.SetReady(newPlayer, true);
            }

            if (NetworkMatch.GetMatchState() != MatchState.PLAYING)
            {
                yield break;
            }

            IntegerMessage modeMsg = new IntegerMessage((int)NetworkMatch.GetMode());

            NetworkServer.SendToClient(connectionId, CustomMsgType.MatchStart, modeMsg);
            SendMatchState(connectionId);

            NetworkSpawnPlayer.Respawn(newPlayer.c_player_ship);
            MPTweaks.Send(connectionId);
            //if (!newPlayer.m_spectator && RearView.MPNetworkMatchEnabled)
            //    newPlayer.CallTargetAddHUDMessage(newPlayer.connectionToClient, "REARVIEW ENABLED", -1, true);
            CTF.SendJoinUpdate(newPlayer);
            Race.SendJoinUpdate(newPlayer);
            foreach (Player player in Overload.NetworkManager.m_Players)
            {
                if (player.connectionToClient.connectionId == connectionId)
                {
                    continue;
                }
                // Resend mode for existing player to move h2h -> anarchy
                NetworkServer.SendToClient(player.connectionToClient.connectionId, CustomMsgType.MatchStart, modeMsg);

                if (!newPlayer.m_spectator)
                {
                    player.CallTargetAddHUDMessage(player.connectionToClient, String.Format(Loc.LS("{0} JOINED MATCH"), newPlayer.m_mp_name), -1, true);
                }

                //Debug.Log("JIP: spawning on new client net " + player.netId + " lobby " + player.connectionToClient.connectionId);
                NetworkServer.SendToClient(connectionId, CustomMsgType.Respawn, new RespawnMessage
                {
                    m_net_id     = player.netId,
                    lobby_id     = player.connectionToClient.connectionId,
                    m_pos        = player.transform.position,
                    m_rotation   = player.transform.rotation,
                    use_loadout1 = player.m_use_loadout1
                });
            }
            ServerStatLog.Connected(newPlayer.m_mp_name);
            MPBanPlayers.ApplyAllBans(); // make sure the newly connected player gets proper treatment if he is BANNED
        }