private static IEnumerator InformClientAboutOlmod(int connectionId, bool customLevel, int delaySeconds)
 {
     if (!MPTweaks.ClientHasMod(connectionId))
     {
         yield return(GameManager.m_gm.StartCoroutine(WaitForMPTweaks(connectionId, 3, 1)));
     }
     if (!NetworkMatch.m_players.ContainsKey(connectionId)) // disconnected?
     {
         yield break;
     }
     if (!MPTweaks.ClientHasMod(connectionId))
     {
         // client does not have olmod
         LobbyChatMessage lmsg = null;
         if (customLevel)
         {
             Debug.LogFormat("client {0} doesn't seem to have olmod, but we use a custom level, warning it", connectionId);
             lmsg = new LobbyChatMessage(connectionId, "Server", MpTeam.TEAM0, "Joining this match might be impossible without OLMod!", false);
             NetworkServer.SendToClient(connectionId, 75, lmsg);
         }
         else
         {
             lmsg = new LobbyChatMessage(connectionId, "Server", MpTeam.TEAM0, "Please install OLMod for enhanced multiplayer experience!", false);
             NetworkServer.SendToClient(connectionId, 75, lmsg);
         }
         lmsg = new LobbyChatMessage(connectionId, "Server", MpTeam.TEAM0, "See olmod.overloadmaps.com for instructions...", false);
         NetworkServer.SendToClient(connectionId, 75, lmsg);
         if (delaySeconds > 0)
         {
             yield return(new WaitForSecondsRealtime((float)(delaySeconds * 10)));
         }
     }
 }
        // helper function to send a lobby chat message
        private static void SendToLobbyHelper(LobbyChatMessage lmsg, int connection_id, bool authOnly, bool unblockedOnly)
        {
            bool doSend = true;

            if (authOnly || unblockedOnly)
            {
                MPBanEntry entry = MPChatCommand.FindPlayerEntryForConnection(connection_id, true);
                if (authOnly)
                {
                    doSend = doSend && MPChatCommand.CheckPermission(entry);
                }
                if (doSend && unblockedOnly)
                {
                    if (entry != null)
                    {
                        doSend = !MPBanPlayers.IsBanned(entry, MPBanMode.BlockChat);
                    }
                    else
                    {
                        doSend = false;
                    }
                }
            }
            if (doSend)
            {
                NetworkServer.SendToClient(connection_id, 75, lmsg);
            }
        }
        private static bool Prefix(int sender_connection_id, LobbyChatMessage msg)
        {
            MpTeam        team = NetworkMatch.GetTeamFromLobbyData(sender_connection_id);
            MPChatCommand cmd  = new MPChatCommand(msg.m_text, sender_connection_id, msg.m_sender_name, team, true);

            return(cmd.Execute());
        }
        private static IEnumerator WaitForMPTweaks(int connectionId, int maxSeconds, int informAfter = -1)
        {
            int cnt = 0;

            while (!MPTweaks.ClientHasMod(connectionId) && cnt < maxSeconds * 10)
            {
                cnt++;
                yield return(new WaitForSecondsRealtime(0.1f));

                if (!NetworkMatch.m_players.ContainsKey(connectionId)) // disconnected?
                {
                    yield break;
                }
                if (cnt == informAfter * 10)
                {
                    // it's already unlikely to be a modded client.
                    LobbyChatMessage lmsg = new LobbyChatMessage(connectionId, "Server", MpTeam.TEAM0, "This server uses OLMod", false);
                    NetworkServer.SendToClient(connectionId, 75, lmsg);
                }
            }
        }
        // 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 authOnly is true, only send to clients which are authenticated for chat
        // commands.
        // If unblockedOnly is true, only send to clients which are not BlockChat-BANNED
        // You need to already know if we are currently in Lobby or not
        public static bool SendTo(bool inLobby, 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)
        {
            bool toAll = (connection_id < 0);

            if (!toAll)
            {
                if (connection_id >= NetworkServer.connections.Count || NetworkServer.connections[connection_id] == null)
                {
                    return(false);
                }
            }

            if (inLobby)
            {
                var lmsg = new LobbyChatMessage(sender_connection_id, sender_name, team, msg, isTeamMessage);
                if (toAll)
                {
                    if (except_connection_id < 0 && !authOnly && !unblockedOnly)
                    {
                        NetworkServer.SendToAll(75, lmsg);
                    }
                    else
                    {
                        foreach (NetworkConnection c in NetworkServer.connections)
                        {
                            if (c != null && c.connectionId != except_connection_id)
                            {
                                SendToLobbyHelper(lmsg, c.connectionId, authOnly, unblockedOnly);
                            }
                        }
                    }
                }
                else
                {
                    SendToLobbyHelper(lmsg, connection_id, authOnly, unblockedOnly);
                }
            }
            else
            {
                if (isTeamMessage)
                {
                    msg = Loc.LS("[TEAM]") + " " + msg;
                }
                foreach (var p in Overload.NetworkManager.m_Players)
                {
                    if (p != null && p.connectionToClient != null)
                    {
                        if ((toAll && p.connectionToClient.connectionId != except_connection_id) || (p.connectionToClient.connectionId == connection_id))
                        {
                            bool doSend = true;
                            if (authOnly || unblockedOnly)
                            {
                                MPBanEntry entry = new MPBanEntry(p);
                                if (authOnly)
                                {
                                    doSend = doSend && MPChatCommand.CheckPermission(entry);
                                }
                                if (doSend && unblockedOnly)
                                {
                                    doSend = !MPBanPlayers.IsBanned(entry, MPBanMode.BlockChat);
                                }
                            }
                            if (doSend)
                            {
                                p.CallTargetSendFullChat(p.connectionToClient, connection_id, sender_name, team, msg);
                            }
                        }
                    }
                }
            }
            return(true);
        }