Ejemplo n.º 1
0
    public override void Connected(BoltConnection connection)
    {
        Bolt.IProtocolToken token = connection.ConnectToken;

        //if this is a development build or in the editor, user authorization is not required
        //this should allow for much faster debugging and testing
        if ((Debug.isDebugBuild || Application.isEditor) && token == null)
        {
            var newToken = new ConnectionRequestData();
            newToken.Password = ServerSideData.Password;
            string baseusername = "******";
            int    suffix       = 0;
            while (PlayerRegistry.UserConnected(baseusername + suffix))
            {
                suffix++;
            }
            string name = baseusername + suffix;
            newToken.PlayerName = name;
            token = newToken;
            DebugNameEvent evnt = DebugNameEvent.Create(connection, Bolt.ReliabilityModes.ReliableOrdered);
            evnt.NewName = name;
            evnt.Send();
        }

        if (token != null && token is ConnectionRequestData)
        {
            ConnectionRequestData data = (ConnectionRequestData)token;
            Debug.Log("connection request with token of type " + token.GetType().Name);
            if (data.Password != ServerSideData.Password)
            {
                connection.Disconnect(new DisconnectReason("Server Refused Connection", "Incorrect Password"));
            }
            else if (PlayerRegistry.UserConnected(data.PlayerName))
            {
                connection.Disconnect(new DisconnectReason("Server Refused Connection", "A player with that name is already connected"));
            }
            else if (GameManager.instance.CurrentGameState == GameManager.GameState.IN_GAME)
            {
                if (!IndexMap.ContainsPlayer(data.PlayerName))
                {
                    connection.Disconnect(new DisconnectReason("Server Refused Connection", "Game already in progress"));
                }
            }
            else
            {
                PlayerRegistry.CreatePlayer(connection, data.PlayerName);
                lobby.AddPlayer(data.PlayerName);
                lobby.SetPlayerStatIndex(data.PlayerName, IndexMap.AddPlayer(data.PlayerName));
                //player connected successfully!
            }
        }
        else
        {
            connection.Disconnect(new DisconnectReason("Server Refused Connection", "Invalid Connection Token"));
        }
    }
Ejemplo n.º 2
0
 public override void Connected(BoltConnection connection)
 {
     connection.SetCanReceiveEntities(false);
     if (CoopPeerStarter.DedicatedHost)
     {
         if (!string.IsNullOrEmpty(CoopDedicatedServerStarter.ServerPassword))
         {
             CoopJoinDedicatedServerToken coopJoinDedicatedServerToken = connection.ConnectToken as CoopJoinDedicatedServerToken;
             if (coopJoinDedicatedServerToken != null && coopJoinDedicatedServerToken.ServerPassword != CoopDedicatedServerStarter.ServerPassword)
             {
                 connection.Disconnect(new CoopJoinDedicatedServerFailed
                 {
                     Error = "Incorrect server password"
                 });
                 return;
             }
         }
         if (!string.IsNullOrEmpty(CoopDedicatedServerStarter.AdminPassword))
         {
             CoopJoinDedicatedServerToken coopJoinDedicatedServerToken2 = connection.ConnectToken as CoopJoinDedicatedServerToken;
             if (coopJoinDedicatedServerToken2 != null && coopJoinDedicatedServerToken2.AdminPassword == CoopDedicatedServerStarter.AdminPassword)
             {
                 AdminAuthed adminAuthed = AdminAuthed.Create(connection);
                 adminAuthed.IsAdmin = true;
                 adminAuthed.Send();
             }
         }
     }
 }
Ejemplo n.º 3
0
 public override void Connected(BoltConnection connection)
 {
     connection.SetCanReceiveEntities(false);
     if (CoopPeerStarter.DedicatedHost)
     {
         if (!string.IsNullOrEmpty(CoopDedicatedServerStarter.ServerPassword))
         {
             CoopJoinDedicatedServerToken coopJoinDedicatedServerToken = connection.ConnectToken as CoopJoinDedicatedServerToken;
             if (coopJoinDedicatedServerToken != null && coopJoinDedicatedServerToken.ServerPassword != CoopDedicatedServerStarter.ServerPassword)
             {
                 connection.Disconnect(new CoopJoinDedicatedServerFailed
                 {
                     Error = "Incorrect server password"
                 });
                 return;
             }
         }
         if (!string.IsNullOrEmpty(CoopDedicatedServerStarter.AdminPassword))
         {
             CoopJoinDedicatedServerToken coopJoinDedicatedServerToken2 = connection.ConnectToken as CoopJoinDedicatedServerToken;
             if (coopJoinDedicatedServerToken2 != null && coopJoinDedicatedServerToken2.AdminPassword == CoopDedicatedServerStarter.AdminPassword)
             {
                 AdminAuthed adminAuthed = AdminAuthed.Create(connection);
                 adminAuthed.IsAdmin = true;
                 adminAuthed.Send();
             }
         }
     }
 }
Ejemplo n.º 4
0
        private object IOnUserApprove(BoltConnection connection)
        {
            var id       = connection.RemoteEndPoint.SteamId.Id.ToString();
            var cSteamId = new CSteamID(connection.RemoteEndPoint.SteamId.Id);
            var name     = SteamFriends.GetFriendPersonaName(cSteamId);
            P2PSessionState_t sessionState;

            SteamGameServerNetworking.GetP2PSessionState(cSteamId, out sessionState);
            var remoteIp = sessionState.m_nRemoteIP;
            var ip       = string.Concat(remoteIp >> 24 & 255, ".", remoteIp >> 16 & 255, ".", remoteIp >> 8 & 255, ".", remoteIp & 255);

            // Call out and see if we should reject
            var canLogin = Interface.Call("CanClientLogin", connection) ?? Interface.Call("CanUserLogin", name, id, ip);

            if (canLogin is string)
            {
                var coopKickToken = new CoopKickToken {
                    KickMessage = canLogin.ToString(), Banned = false
                };
                connection.Disconnect(coopKickToken);
                return(true);
            }

            return(Interface.Call("OnUserApprove", connection) ?? Interface.Call("OnUserApproved", name, id, ip));
        }
Ejemplo n.º 5
0
    public override void Connected(BoltConnection connection)
    {
        if (SteamHub.LobbyActive != null && SteamManager.Initialized)
        {
            var  token       = (SteamToken)connection.ConnectToken;
            var  activeLobby = SteamHub.LobbyActive;
            bool found       = false;

            foreach (var m in activeLobby.AllMembers)
            {
                if (m.m_SteamID == token.SteamID)
                {
                    connection.UserData = "CLIENT:" + SteamFriends.GetFriendPersonaName(m) + " " + connection.RemoteEndPoint.Port;
                    Debug.Log(connection.UserData);
                    found = true;
                    break;
                }
            }

            if (found == false)
            {
                connection.Disconnect();
            }
        }
    }
Ejemplo n.º 6
0
        private object IOnUserApprove(BoltConnection connection)
        {
            var id       = connection.RemoteEndPoint.SteamId.Id.ToString();
            var cSteamId = new CSteamID(connection.RemoteEndPoint.SteamId.Id);

            // Get IP address from Steam
            P2PSessionState_t sessionState;

            SteamGameServerNetworking.GetP2PSessionState(cSteamId, out sessionState);
            var remoteIp = sessionState.m_nRemoteIP;
            var ip       = string.Concat(remoteIp >> 24 & 255, ".", remoteIp >> 16 & 255, ".", remoteIp >> 8 & 255, ".", remoteIp & 255);

            // Call out and see if we should reject
            var canLogin = Interface.Call("CanClientLogin", connection) ?? Interface.Call("CanUserLogin", "Unnamed", id, ip);

            if (canLogin is string || (canLogin is bool && !(bool)canLogin))
            {
                var coopKickToken = new CoopKickToken
                {
                    KickMessage = canLogin is string?canLogin.ToString() : "Connection was rejected",   // TODO: Localization
                                      Banned = false
                };
                connection.Disconnect(coopKickToken);
                return(true);
            }

            return(Interface.Call("OnUserApprove", connection) ?? Interface.Call("OnUserApproved", "Unnamed", id, ip));
        }
    public override void Connected(BoltConnection connection)
    {
        Bolt.IProtocolToken token = connection.ConnectToken;

        //if this is a development build or in the editor, user authorization is not required
        //this should allow for much faster debugging and testing
        if ((Debug.isDebugBuild || Application.isEditor) && token == null) {
            var newToken = new ConnectionRequestData();
            newToken.Password = ServerSideData.Password;
            string baseusername = "******";
            int suffix = 0;
            while (PlayerRegistry.UserConnected(baseusername + suffix)) suffix++;
            string name = baseusername + suffix;
            newToken.PlayerName = name;
            token = newToken;
            DebugNameEvent evnt = DebugNameEvent.Create(connection, Bolt.ReliabilityModes.ReliableOrdered);
            evnt.NewName = name;
            evnt.Send();
        }

        if (token != null && token is ConnectionRequestData) {
            ConnectionRequestData data = (ConnectionRequestData)token;
            Debug.Log("connection request with token of type " + token.GetType().Name);
            if (data.Password != ServerSideData.Password) {
                connection.Disconnect(new DisconnectReason("Server Refused Connection", "Incorrect Password"));
            } else if (PlayerRegistry.UserConnected(data.PlayerName)) {
                connection.Disconnect(new DisconnectReason("Server Refused Connection", "A player with that name is already connected"));
            } else if(GameManager.instance.CurrentGameState == GameManager.GameState.IN_GAME){
                if (!IndexMap.ContainsPlayer(data.PlayerName)) {
                    connection.Disconnect(new DisconnectReason("Server Refused Connection", "Game already in progress"));
                }
            } else{
                PlayerRegistry.CreatePlayer(connection, data.PlayerName);
                lobby.AddPlayer(data.PlayerName);
                lobby.SetPlayerStatIndex(data.PlayerName, IndexMap.AddPlayer(data.PlayerName));
                //player connected successfully!
            }
        } else {
            connection.Disconnect(new DisconnectReason("Server Refused Connection", "Invalid Connection Token"));
        }
    }
Ejemplo n.º 8
0
 void OnSpawn(PlayerConnection connection, string creature, string gadget, string armor, Vector3 position, float yaw)
 {
     if (bans.Contains(connection.SteamID.m_SteamID.ToString()))
     {
         BoltConnection boltConnection = connection.BoltConnection;
         RefuseToken    refuseToken1   = new RefuseToken();
         refuseToken1.RefuseReason = "Banned by admin.";
         RefuseToken refuseToken2 = refuseToken1;
         boltConnection.Disconnect((IProtocolToken)refuseToken2);
     }
     BoltGlobalEvent.SendObjectiveEvent(spwnmsg, "Alert", new Color32(255, 133, 0, 255), connection.BoltConnection);
 }
Ejemplo n.º 9
0
 public override void Connected(BoltConnection connection)
 {
     connection.SetCanReceiveEntities(false);
     if (CoopKick.IsBanned(connection.RemoteEndPoint.SteamId))
     {
         connection.Disconnect(new CoopKickToken
         {
             Banned      = true,
             KickMessage = "HOST_BANNED_YOU_PERMANANTLY"
         });
     }
     else
     {
         CoopServerInfo.Instance.entity.Freeze(false);
     }
 }
Ejemplo n.º 10
0
        private object IOnUserApprove(BoltConnection connection)
        {
            CSteamID cSteamId = SteamDSConfig.clientConnectionInfo[connection.ConnectionId];
            string   playerId = cSteamId.ToString();
            ulong    steamId  = cSteamId.m_SteamID;

            // Check for existing player's name
            IPlayer player = Covalence.PlayerManager.FindPlayerById(playerId);
            string  name   = !string.IsNullOrEmpty(player?.Name) ? player.Name : "Unnamed";

            // Handle universal player joining
            Covalence.PlayerManager.PlayerJoin(steamId, name);

            // Get IP address from Steam
            SteamGameServerNetworking.GetP2PSessionState(cSteamId, out P2PSessionState_t sessionState);
            uint   remoteIp = sessionState.m_nRemoteIP;
            string playerIp = string.Concat(remoteIp >> 24 & 255, ".", remoteIp >> 16 & 255, ".", remoteIp >> 8 & 255, ".", remoteIp & 255);

            // Call out and see if we should reject
            object loginSpecific  = Interface.Call("CanClientLogin", connection);
            object loginCovalence = Interface.Call("CanUserLogin", name, playerId, playerIp);
            object canLogin       = loginSpecific is null ? loginCovalence : loginSpecific;

            if (!serverInitialized || canLogin is string || canLogin is bool loginBlocked && !loginBlocked)
            {
                // Create kick token for player
                CoopKickToken coopKickToken = new CoopKickToken
                {
                    KickMessage = !serverInitialized ? "Server not initialized yet" : canLogin is string?canLogin.ToString() : "Connection was rejected",   // TODO: Localization
                                      Banned = false
                };

                // Disconnect player using kick token
                connection.Disconnect(coopKickToken);
                return(true);
            }

            // Call hooks for plugins
            object approvedSpecific  = Interface.Call("OnUserApprove", connection);
            object approvedCovalence = Interface.Call("OnUserApproved", name, playerId, playerIp);

            return(approvedSpecific is null ? approvedCovalence : approvedSpecific);
        }
Ejemplo n.º 11
0
 public static void KickPlayer(BoltConnection connection, BoltEntity playerEntity, int duration, string message = "HOST_KICKED_YOU")
 {
     if (!BoltNetwork.isServer)
     {
         return;
     }
     if (connection == null && playerEntity == null)
     {
         return;
     }
     if (connection == null)
     {
         connection = playerEntity.source;
     }
     try
     {
         ulong steamId = CoopKick.GetSteamId(connection);
         if (steamId == 0UL)
         {
             steamId = CoopKick.GetSteamId(playerEntity);
         }
         string name = (!(playerEntity == null)) ? playerEntity.GetState <IPlayerState>().name : steamId.ToString();
         if (duration >= 0 && steamId > 0UL && !CoopKick.IsBanned(steamId))
         {
             CoopKick.Instance.kickedSteamIds.Add(new CoopKick.KickedPlayer
             {
                 Name       = name,
                 SteamId    = steamId,
                 BanEndTime = ((duration <= 0) ? 0L : (DateTime.UtcNow.ToUnixTimestamp() + (long)duration))
             });
             CoopKick.SaveList();
         }
     }
     catch (Exception exception)
     {
         Debug.LogException(exception);
     }
     connection.Disconnect(new CoopKickToken
     {
         KickMessage = message,
         Banned      = (duration == 0)
     });
 }
Ejemplo n.º 12
0
 public override void Connected(BoltConnection connection)
 {
     if (BoltNetwork.isServer)
     {
         if (CoopKick.IsBanned(connection.RemoteEndPoint.SteamId))
         {
             connection.Disconnect(new CoopKickToken
             {
                 Banned = true,
                 KickMessage = "Host banned you from his games"
             });
         }
         else
         {
             ClientACK.Create(connection).Send();
         }
     }
     if (!CoopPeerStarter.DedicatedHost && Scene.HudGui && Scene.HudGui.MpPlayerList && Scene.HudGui.MpPlayerList.gameObject && Scene.HudGui.MpPlayerList.gameObject.activeInHierarchy)
     {
         Scene.HudGui.MpPlayerList.Refresh();
     }
 }
Ejemplo n.º 13
0
 public override void Connected(BoltConnection connection)
 {
     if (BoltNetwork.isServer)
     {
         if (CoopKick.IsBanned(connection.RemoteEndPoint.SteamId))
         {
             connection.Disconnect(new CoopKickToken
             {
                 Banned      = true,
                 KickMessage = "Host banned you from his games"
             });
         }
         else
         {
             ClientACK.Create(connection).Send();
         }
     }
     if (!CoopPeerStarter.DedicatedHost && Scene.HudGui && Scene.HudGui.MpPlayerList && Scene.HudGui.MpPlayerList.gameObject && Scene.HudGui.MpPlayerList.gameObject.activeInHierarchy)
     {
         Scene.HudGui.MpPlayerList.Refresh();
     }
 }
Ejemplo n.º 14
0
        object OnPlayerJoinMatch(PlayerConnection connection)
        {
            if (bans.Contains(connection.SteamID.m_SteamID.ToString()))
            {
                BoltConnection boltConnection = connection.BoltConnection;
                RefuseToken    refuseToken1   = new RefuseToken();
                refuseToken1.RefuseReason = "Banned by admin.";
                RefuseToken refuseToken2 = refuseToken1;
                boltConnection.Disconnect((IProtocolToken)refuseToken2);
                return(true);
            }

            if (BoltNetwork.connections.Count() >= SteamHeadless.RoomPlayerLimit - vipslots && !vip.Contains(connection.SteamID.m_SteamID.ToString()))
            {
                BoltConnection boltConnection = connection.BoltConnection;
                RefuseToken    refuseToken1   = new RefuseToken();
                refuseToken1.RefuseReason = "the server has reserved slots.";
                RefuseToken refuseToken2 = refuseToken1;
                boltConnection.Disconnect((IProtocolToken)refuseToken2);
                return(true);
            }
            return(null);
        }
Ejemplo n.º 15
0
 public override void Connected(BoltConnection connection)
 {
     if (BoltNetwork.isServer)
     {
         if (CoopKick.IsBanned(connection.RemoteEndPoint.SteamId))
         {
             Debug.Log("TELL CLIENT HE WAS BANNED");
             connection.Disconnect(new CoopKickToken
             {
                 Banned      = true,
                 KickMessage = "HOST_BANNED_YOU"
             });
         }
         else
         {
             ClientACK.Create(connection).Send();
             CoopTreeGrid.TodoPlayerSweeps.Add(connection);
         }
     }
     if (!CoopPeerStarter.DedicatedHost && Scene.HudGui && Scene.HudGui.MpPlayerList && Scene.HudGui.MpPlayerList.gameObject && Scene.HudGui.MpPlayerList.gameObject.activeInHierarchy)
     {
         Scene.HudGui.MpPlayerList.Refresh();
     }
 }
Ejemplo n.º 16
0
        // chat commands:
        // /kick <username>
        // /kickid <steam64id>
        // /ssay <message to say as server>
        // /ban <>
        // /banid <>
        // /rl
        // /reload
        // unban <>
        object OnEvent(ChatEvent ev)
        {
            string user = ev.RaisedBy.GetPlayerConnection().SteamID.m_SteamID.ToString();

            if (bans.Contains(user))
            {
                BoltConnection boltConnection = ev.RaisedBy;
                RefuseToken    refuseToken1   = new RefuseToken();
                refuseToken1.RefuseReason = "Banned by admin.";
                RefuseToken refuseToken2 = refuseToken1;
                boltConnection.Disconnect((IProtocolToken)refuseToken2);
                return(true);
            }

            if (admins.IndexOf(user) == -1)
            {
                return(null);
            }
            string cmd = ev.Text;

            if (cmd.StartsWith("/"))
            {
                ev.Text = "";
            }
            else
            {
                return(null);
            }
            //ssay
            if (cmd.StartsWith("/ssay "))
            {
                string[] args     = cmd.Split(' ');
                string   kickuser = "";
                for (int i = 1; i < args.Length; i++)
                {
                    kickuser += args[i];
                    if (i < args.Length)
                    {
                        kickuser += " ";
                    }
                }
                if (kickuser != "" && args.Length > 2)
                {
                    BoltGlobalEvent.SendMessage("<color=#CCCCCC>[<color=red>Server<color=#CCCCCC>] Says: " + kickuser, (Color32)Color.white);
                }
                else
                {
                    BoltGlobalEvent.SendPrivateMessage("/ssay <server message 2+ words long>", new Color32(255, 0, 0, 255), ev.RaisedBy);
                }
                ev.Text = "";
            }
            //rl or reload
            if (cmd.StartsWith("/rl") || cmd.StartsWith("/reload"))
            {
                LoadConfig();
                try
                {
                    admins = ((IEnumerable <object>)Config["admins"]).OfType <string>().ToList();
                }
                catch (Exception e)
                {
                    Puts("Unable to load admins");
                    BoltGlobalEvent.SendPrivateMessage("Unable to load admins", new Color32(255, 0, 0, 255), ev.RaisedBy);
                }
                try
                {
                    bans = ((IEnumerable <object>)Config["bans"]).OfType <string>().ToList();
                }
                catch (Exception e)
                {
                    Puts("Unable to load bans!");
                    BoltGlobalEvent.SendPrivateMessage("Unable to load bans!", new Color32(255, 0, 0, 255), ev.RaisedBy);
                    Debug.Log("Unable to load bans!");
                }
                try
                {
                    vipslots = (int)Config["vipslots"];
                }
                catch (Exception e)
                {
                    Puts("Unable to load vipslots");
                    BoltGlobalEvent.SendPrivateMessage("Unable to load vipslots", new Color32(255, 0, 0, 255), ev.RaisedBy);
                }
                try
                {
                    vip = ((IEnumerable <object>)Config["vip"]).OfType <string>().ToList();
                }
                catch (Exception e)
                {
                    Puts("Unable to load vip");
                    BoltGlobalEvent.SendPrivateMessage("Unable to load vip", new Color32(255, 0, 0, 255), ev.RaisedBy);
                }
                try
                {
                    spwnmsg = (string)Config["SpawnMessage"];
                }
                catch (Exception e)
                {
                    Puts("Unable to load spawnmsg");
                    BoltGlobalEvent.SendPrivateMessage("Unable to load spawnmsg", new Color32(255, 0, 0, 255), ev.RaisedBy);
                }
                ev.Text = "";
            }
            //unban
            if (cmd.StartsWith("/unban "))
            {
                string[] args     = cmd.Split(' ');
                string   kickuser = "";
                for (int i = 1; i < args.Length; i++)
                {
                    kickuser += args[i];
                    if (i < args.Length - 1)
                    {
                        kickuser += " ";
                    }
                }
                if (kickuser != "" && bans.Contains(kickuser))
                {
                    bans.Remove(kickuser);
                    Config["bans"] = bans;
                    SaveConfig();
                    BoltGlobalEvent.SendMessage("<color=#CCCCCC>[<color=red>Server<color=#CCCCCC>] Unbanned: " + kickuser, (Color32)Color.white);
                }
                else
                {
                    BoltGlobalEvent.SendPrivateMessage("/unban <steam64id>", new Color32(255, 0, 0, 255), ev.RaisedBy);
                }
                ev.Text = "";
            }
            //banid
            if (cmd.StartsWith("/banid "))
            {
                string[] args     = cmd.Split(' ');
                string   kickuser = "";
                for (int i = 1; i < args.Length; i++)
                {
                    kickuser += args[i];
                    if (i < args.Length - 1)
                    {
                        kickuser += " ";
                    }
                }
                if (kickuser != "")
                {
                    using (IEnumerator <BoltConnection> enumerator = BoltNetwork.connections.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            BoltConnection current = enumerator.Current;
                            if (current.GetPlayerConnection().PlayerInfo.state.SteamID.ToString() == kickuser)
                            {
                                bans.Add(kickuser);
                                Config["bans"] = bans;
                                SaveConfig();
                                BoltGlobalEvent.SendMessage("<color=#CCCCCC>[<color=red>Server<color=#CCCCCC>] Banned: " + current.GetPlayerConnection().PlayerInfo.state.PenName, (Color32)Color.white);
                                BoltConnection boltConnection = current;
                                RefuseToken    refuseToken1   = new RefuseToken();
                                refuseToken1.RefuseReason = "Banned by admin.";
                                RefuseToken refuseToken2 = refuseToken1;
                                boltConnection.Disconnect((IProtocolToken)refuseToken2);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    BoltGlobalEvent.SendPrivateMessage("/kickid <steamid>", new Color32(255, 0, 0, 255), ev.RaisedBy);
                }
                ev.Text = "";
            }
            //ban
            if (cmd.StartsWith("/ban "))
            {
                string[] args     = cmd.Split(' ');
                string   kickuser = "";
                for (int i = 1; i < args.Length; i++)
                {
                    kickuser += args[i];
                    if (i + 1 < args.Length)
                    {
                        kickuser += " ";
                    }
                }
                if (kickuser != "")
                {
                    using (IEnumerator <BoltConnection> enumerator = BoltNetwork.connections.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            BoltConnection current = enumerator.Current;
                            string         newname = current.GetPlayerConnection().PlayerInfo.state.PenName.Substring(9, current.GetPlayerConnection().PlayerInfo.state.PenName.Length - 19);
                            if (newname.ToLower().IndexOf(kickuser.ToLower()) != -1 && current.GetPlayerConnection().PlayerInfo.state.SteamID != user)
                            {
                                bans.Add(current.GetPlayerConnection().PlayerInfo.state.SteamID);
                                Config["bans"] = bans;
                                SaveConfig();
                                BoltGlobalEvent.SendMessage("<color=#CCCCCC>[<color=red>Server<color=#CCCCCC>] Banned: " + current.GetPlayerConnection().PlayerInfo.state.PenName, (Color32)Color.white);
                                BoltConnection boltConnection = current;
                                RefuseToken    refuseToken1   = new RefuseToken();
                                refuseToken1.RefuseReason = "Banned by admin.";
                                RefuseToken refuseToken2 = refuseToken1;
                                boltConnection.Disconnect((IProtocolToken)refuseToken2);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    BoltGlobalEvent.SendPrivateMessage("/kick <username>", new Color32(255, 0, 0, 255), ev.RaisedBy);
                }
                ev.Text = "";
            }
            //kickid
            if (cmd.StartsWith("/kickid "))
            {
                string[] args     = cmd.Split(' ');
                string   kickuser = "";
                for (int i = 1; i < args.Length; i++)
                {
                    kickuser += args[i];
                    if (i < args.Length)
                    {
                        kickuser += " ";
                    }
                }
                if (kickuser != "")
                {
                    using (IEnumerator <BoltConnection> enumerator = BoltNetwork.connections.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            BoltConnection current = enumerator.Current;
                            if (current.GetPlayerConnection().PlayerInfo.state.SteamID.ToString() == kickuser)
                            {
                                BoltGlobalEvent.SendMessage("<color=#CCCCCC>[<color=red>Server<color=#CCCCCC>] Kicked: " + current.GetPlayerConnection().PlayerInfo.state.PenName, (Color32)Color.white);
                                BoltConnection boltConnection = current;
                                RefuseToken    refuseToken1   = new RefuseToken();
                                refuseToken1.RefuseReason = "Kicked by admin.";
                                RefuseToken refuseToken2 = refuseToken1;
                                boltConnection.Disconnect((IProtocolToken)refuseToken2);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    BoltGlobalEvent.SendPrivateMessage("/kickid <steamid>", new Color32(255, 0, 0, 255), ev.RaisedBy);
                }
                ev.Text = "";
            }
            //kick
            if (cmd.StartsWith("/kick "))
            {
                string[] args     = cmd.Split(' ');
                string   kickuser = "";
                for (int i = 1; i < args.Length; i++)
                {
                    kickuser += args[i];
                    if (i + 1 < args.Length)
                    {
                        kickuser += " ";
                    }
                }
                if (kickuser != "")
                {
                    using (IEnumerator <BoltConnection> enumerator = BoltNetwork.connections.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            BoltConnection current = enumerator.Current;
                            string         newname = current.GetPlayerConnection().PlayerInfo.state.PenName.Substring(9, current.GetPlayerConnection().PlayerInfo.state.PenName.Length - 19);
                            if (newname.ToLower().IndexOf(kickuser.ToLower()) != -1 && current.GetPlayerConnection().PlayerInfo.state.SteamID != user)
                            {
                                BoltGlobalEvent.SendMessage("<color=#CCCCCC>[<color=red>Server<color=#CCCCCC>] Kicked: " + current.GetPlayerConnection().PlayerInfo.state.PenName, (Color32)Color.white);
                                BoltConnection boltConnection = current;
                                RefuseToken    refuseToken1   = new RefuseToken();
                                refuseToken1.RefuseReason = "Kicked by admin.";
                                RefuseToken refuseToken2 = refuseToken1;
                                boltConnection.Disconnect((IProtocolToken)refuseToken2);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    BoltGlobalEvent.SendPrivateMessage("/kick <username>", new Color32(255, 0, 0, 255), ev.RaisedBy);
                }
                ev.Text = "";
            }
            if (cmd.Equals("/speed"))
            {
                foreach (Scram.PlayerController playerController in UnityEngine.Object.FindObjectsOfType <Scram.PlayerController>())
                {
                    if (playerController.entity.controller != null && playerController.entity.controller.GetPlayerConnection().SteamID.m_SteamID.ToString() == user)
                    {
                        playerController.state.playerSpeedModifier = 3f;
                        BoltGlobalEvent.SendPrivateMessage("Speed set to 3", new Color32(255, 0, 255, 255), ev.RaisedBy);
                    }
                }
                ev.Text = "";
            }
            if (cmd.Equals("/clr"))
            {
                foreach (Scram.PlayerController playerController in UnityEngine.Object.FindObjectsOfType <Scram.PlayerController>())
                {
                    if (playerController.entity.controller != null && playerController.entity.controller.GetPlayerConnection().SteamID.m_SteamID.ToString() == user)
                    {
                        playerController.state.playerSpeedModifier = 1f;
                        playerController.state.playerScale         = 1f;
                        playerController.state.unlimitedAmmo       = false;
                        playerController.state.IsInvincible        = false;
                        BoltGlobalEvent.SendPrivateMessage("Cleared all modifiers", new Color32(255, 0, 255, 255), ev.RaisedBy);
                    }
                }
                ev.Text = "";
            }
            if (cmd.Equals("/big"))
            {
                foreach (Scram.PlayerController playerController in UnityEngine.Object.FindObjectsOfType <Scram.PlayerController>())
                {
                    if (playerController.entity.controller != null && playerController.entity.controller.GetPlayerConnection().SteamID.m_SteamID.ToString() == user)
                    {
                        playerController.state.playerScale = Mathf.Min(6f, playerController.state.playerScale + 0.1f);
                        BoltGlobalEvent.SendPrivateMessage("You are bigger", new Color32(255, 0, 255, 255), ev.RaisedBy);
                    }
                }
                ev.Text = "";
            }
            if (cmd.Equals("/small"))
            {
                foreach (Scram.PlayerController playerController in UnityEngine.Object.FindObjectsOfType <Scram.PlayerController>())
                {
                    if (playerController.entity.controller != null && playerController.entity.controller.GetPlayerConnection().SteamID.m_SteamID.ToString() == user)
                    {
                        playerController.state.playerScale = Mathf.Max(0.35f, playerController.state.playerScale - 0.1f);
                        BoltGlobalEvent.SendPrivateMessage("You are smaller", new Color32(255, 0, 255, 255), ev.RaisedBy);
                    }
                }
                ev.Text = "";
            }
            if (cmd.StartsWith("/size "))
            {
                foreach (Scram.PlayerController playerController in UnityEngine.Object.FindObjectsOfType <Scram.PlayerController>())
                {
                    if (playerController.entity.controller != null && playerController.entity.controller.GetPlayerConnection().SteamID.m_SteamID.ToString() == user)
                    {
                        string[] args = cmd.Split(' ');
                        if (args.Length == 2)
                        {
                            float number = 1;
                            float.TryParse(args[1], out number);
                            playerController.state.playerScale = number;
                            BoltGlobalEvent.SendPrivateMessage("Set size to " + number.ToString(), new Color32(255, 0, 255, 255), ev.RaisedBy);
                        }
                    }
                }
                ev.Text = "";
            }
            if (cmd.Equals("/ammo"))
            {
                foreach (Scram.PlayerController playerController in UnityEngine.Object.FindObjectsOfType <Scram.PlayerController>())
                {
                    if (playerController.entity.controller != null && playerController.entity.controller.GetPlayerConnection().SteamID.m_SteamID.ToString() == user)
                    {
                        playerController.state.unlimitedAmmo = !playerController.state.unlimitedAmmo;
                        BoltGlobalEvent.SendPrivateMessage("Unlimited ammo set to " + playerController.state.unlimitedAmmo, new Color32(255, 0, 255, 255), ev.RaisedBy);
                    }
                }
                ev.Text = "";
            }
            if (cmd.Equals("/god"))
            {
                foreach (Scram.PlayerController playerController in UnityEngine.Object.FindObjectsOfType <Scram.PlayerController>())
                {
                    if (playerController.entity.controller != null && playerController.entity.controller.GetPlayerConnection().SteamID.m_SteamID.ToString() == user)
                    {
                        playerController.state.IsInvincible = !playerController.state.IsInvincible;
                        BoltGlobalEvent.SendPrivateMessage("Invincibility set to " + playerController.state.IsInvincible, new Color32(255, 0, 255, 255), ev.RaisedBy);
                    }
                }
                ev.Text = "";
            }
            if (cmd.Equals("/slow"))
            {
                foreach (Scram.PlayerController playerController in UnityEngine.Object.FindObjectsOfType <Scram.PlayerController>())
                {
                    if (playerController.entity.controller != null && playerController.entity.controller.GetPlayerConnection().SteamID.m_SteamID.ToString() == user)
                    {
                        playerController.state.playerSpeedModifier = 1f;
                        BoltGlobalEvent.SendPrivateMessage("Speed set to 1", new Color32(255, 0, 255, 255), ev.RaisedBy);
                    }
                }
                ev.Text = "";
            }
            if (cmd.StartsWith("/"))
            {
                ev.Text = "";
            }
            return(true);
        }
Ejemplo n.º 17
0
        // chat commands:
        // /kick <username>
        // /kickid <steam64id>
        // /ssay <message to say as server>
        // /ban <>
        // /banid <>
        // /rl
        // /reload
        // unban <>
        object OnEvent(ChatEvent ev)
        {
            string user = ev.RaisedBy.GetPlayerConnection().SteamID.m_SteamID.ToString();

            if (bans.Contains(user))
            {
                BoltConnection boltConnection = ev.RaisedBy;
                RefuseToken    refuseToken1   = new RefuseToken();
                refuseToken1.RefuseReason = "Banned by admin.";
                RefuseToken refuseToken2 = refuseToken1;
                boltConnection.Disconnect((IProtocolToken)refuseToken2);
                return(true);
            }

            if (admins.IndexOf(user) == -1)
            {
                return(null);
            }
            string cmd = ev.Text;

            if (cmd.StartsWith("/"))
            {
                ev.Text = "";
            }
            else
            {
                return(null);
            }
            //ssay
            if (cmd.StartsWith("/ssay "))
            {
                string[] args     = cmd.Split(' ');
                string   kickuser = "";
                for (int i = 1; i < args.Length; i++)
                {
                    kickuser += args[i];
                    if (i < args.Length)
                    {
                        kickuser += " ";
                    }
                }
                if (kickuser != "" && args.Length > 2)
                {
                    BoltGlobalEvent.SendMessage("<color=#CCCCCC>[<color=red>Server<color=#CCCCCC>] Says: " + kickuser, (Color32)Color.white);
                }
                else
                {
                    BoltGlobalEvent.SendPrivateMessage("/ssay <server message 2+ words long>", new Color32(255, 0, 0, 255), ev.RaisedBy);
                }
                ev.Text = "";
            }
            //rl or reload
            if (cmd.StartsWith("/rl") || cmd.StartsWith("/reload"))
            {
                LoadConfig();
                try
                {
                    admins = ((IEnumerable <object>)Config["admins"]).OfType <string>().ToList();
                }
                catch (Exception e)
                {
                    Puts("Unable to load admins");
                    BoltGlobalEvent.SendPrivateMessage("Unable to load admins", new Color32(255, 0, 0, 255), ev.RaisedBy);
                }
                try
                {
                    bans = ((IEnumerable <object>)Config["bans"]).OfType <string>().ToList();
                }
                catch (Exception e)
                {
                    Puts("Unable to load bans!");
                    BoltGlobalEvent.SendPrivateMessage("Unable to load bans!", new Color32(255, 0, 0, 255), ev.RaisedBy);
                    Debug.Log("Unable to load bans!");
                }
                try
                {
                    vipslots = (int)Config["vipslots"];
                }
                catch (Exception e)
                {
                    Puts("Unable to load vipslots");
                    BoltGlobalEvent.SendPrivateMessage("Unable to load vipslots", new Color32(255, 0, 0, 255), ev.RaisedBy);
                }
                try
                {
                    vip = ((IEnumerable <object>)Config["vip"]).OfType <string>().ToList();
                }
                catch (Exception e)
                {
                    Puts("Unable to load vip");
                    BoltGlobalEvent.SendPrivateMessage("Unable to load vip", new Color32(255, 0, 0, 255), ev.RaisedBy);
                }
                try
                {
                    spwnmsg = (string)Config["SpawnMessage"];
                }
                catch (Exception e)
                {
                    Puts("Unable to load spawnmsg");
                    BoltGlobalEvent.SendPrivateMessage("Unable to load spawnmsg", new Color32(255, 0, 0, 255), ev.RaisedBy);
                }
                ev.Text = "";
            }
            //unban
            if (cmd.StartsWith("/unban "))
            {
                string[] args     = cmd.Split(' ');
                string   kickuser = "";
                for (int i = 1; i < args.Length; i++)
                {
                    kickuser += args[i];
                    if (i < args.Length - 1)
                    {
                        kickuser += " ";
                    }
                }
                if (kickuser != "" && bans.Contains(kickuser))
                {
                    bans.Remove(kickuser);
                    Config["bans"] = bans;
                    SaveConfig();
                    BoltGlobalEvent.SendMessage("<color=#CCCCCC>[<color=red>Server<color=#CCCCCC>] Unbanned: " + kickuser, (Color32)Color.white);
                }
                else
                {
                    BoltGlobalEvent.SendPrivateMessage("/unban <steam64id>", new Color32(255, 0, 0, 255), ev.RaisedBy);
                }
                ev.Text = "";
            }
            //banid
            if (cmd.StartsWith("/banid "))
            {
                string[] args     = cmd.Split(' ');
                string   kickuser = "";
                for (int i = 1; i < args.Length; i++)
                {
                    kickuser += args[i];
                    if (i < args.Length - 1)
                    {
                        kickuser += " ";
                    }
                }
                if (kickuser != "")
                {
                    using (IEnumerator <BoltConnection> enumerator = BoltNetwork.connections.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            BoltConnection current = enumerator.Current;
                            if (current.GetPlayerConnection().PlayerInfo.state.SteamID.ToString() == kickuser)
                            {
                                bans.Add(kickuser);
                                Config["bans"] = bans;
                                SaveConfig();
                                BoltGlobalEvent.SendMessage("<color=#CCCCCC>[<color=red>Server<color=#CCCCCC>] Banned: " + current.GetPlayerConnection().PlayerInfo.state.PenName, (Color32)Color.white);
                                BoltConnection boltConnection = current;
                                RefuseToken    refuseToken1   = new RefuseToken();
                                refuseToken1.RefuseReason = "Banned by admin.";
                                RefuseToken refuseToken2 = refuseToken1;
                                boltConnection.Disconnect((IProtocolToken)refuseToken2);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    BoltGlobalEvent.SendPrivateMessage("/kickid <steamid>", new Color32(255, 0, 0, 255), ev.RaisedBy);
                }
                ev.Text = "";
            }
            //ban
            if (cmd.StartsWith("/ban "))
            {
                string[] args     = cmd.Split(' ');
                string   kickuser = "";
                for (int i = 1; i < args.Length; i++)
                {
                    kickuser += args[i];
                    if (i + 1 < args.Length)
                    {
                        kickuser += " ";
                    }
                }
                if (kickuser != "")
                {
                    using (IEnumerator <BoltConnection> enumerator = BoltNetwork.connections.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            BoltConnection current = enumerator.Current;
                            string         newname = current.GetPlayerConnection().PlayerInfo.state.PenName.Substring(9, current.GetPlayerConnection().PlayerInfo.state.PenName.Length - 19);
                            if (newname.ToLower().IndexOf(kickuser.ToLower()) != -1 && current.GetPlayerConnection().PlayerInfo.state.SteamID != user)
                            {
                                bans.Add(current.GetPlayerConnection().PlayerInfo.state.SteamID);
                                Config["bans"] = bans;
                                SaveConfig();
                                BoltGlobalEvent.SendMessage("<color=#CCCCCC>[<color=red>Server<color=#CCCCCC>] Banned: " + current.GetPlayerConnection().PlayerInfo.state.PenName, (Color32)Color.white);
                                BoltConnection boltConnection = current;
                                RefuseToken    refuseToken1   = new RefuseToken();
                                refuseToken1.RefuseReason = "Banned by admin.";
                                RefuseToken refuseToken2 = refuseToken1;
                                boltConnection.Disconnect((IProtocolToken)refuseToken2);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    BoltGlobalEvent.SendPrivateMessage("/kick <username>", new Color32(255, 0, 0, 255), ev.RaisedBy);
                }
                ev.Text = "";
            }
            //kickid
            if (cmd.StartsWith("/kickid "))
            {
                string[] args     = cmd.Split(' ');
                string   kickuser = "";
                for (int i = 1; i < args.Length; i++)
                {
                    kickuser += args[i];
                    if (i < args.Length)
                    {
                        kickuser += " ";
                    }
                }
                if (kickuser != "")
                {
                    using (IEnumerator <BoltConnection> enumerator = BoltNetwork.connections.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            BoltConnection current = enumerator.Current;
                            if (current.GetPlayerConnection().PlayerInfo.state.SteamID.ToString() == kickuser)
                            {
                                BoltGlobalEvent.SendMessage("<color=#CCCCCC>[<color=red>Server<color=#CCCCCC>] Kicked: " + current.GetPlayerConnection().PlayerInfo.state.PenName, (Color32)Color.white);
                                BoltConnection boltConnection = current;
                                RefuseToken    refuseToken1   = new RefuseToken();
                                refuseToken1.RefuseReason = "Kicked by admin.";
                                RefuseToken refuseToken2 = refuseToken1;
                                boltConnection.Disconnect((IProtocolToken)refuseToken2);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    BoltGlobalEvent.SendPrivateMessage("/kickid <steamid>", new Color32(255, 0, 0, 255), ev.RaisedBy);
                }
                ev.Text = "";
            }
            //kick
            if (cmd.StartsWith("/kick "))
            {
                string[] args     = cmd.Split(' ');
                string   kickuser = "";
                for (int i = 1; i < args.Length; i++)
                {
                    kickuser += args[i];
                    if (i + 1 < args.Length)
                    {
                        kickuser += " ";
                    }
                }
                if (kickuser != "")
                {
                    using (IEnumerator <BoltConnection> enumerator = BoltNetwork.connections.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            BoltConnection current = enumerator.Current;
                            string         newname = current.GetPlayerConnection().PlayerInfo.state.PenName.Substring(9, current.GetPlayerConnection().PlayerInfo.state.PenName.Length - 19);
                            if (newname.ToLower().IndexOf(kickuser.ToLower()) != -1 && current.GetPlayerConnection().PlayerInfo.state.SteamID != user)
                            {
                                BoltGlobalEvent.SendMessage("<color=#CCCCCC>[<color=red>Server<color=#CCCCCC>] Kicked: " + current.GetPlayerConnection().PlayerInfo.state.PenName, (Color32)Color.white);
                                BoltConnection boltConnection = current;
                                RefuseToken    refuseToken1   = new RefuseToken();
                                refuseToken1.RefuseReason = "Kicked by admin.";
                                RefuseToken refuseToken2 = refuseToken1;
                                boltConnection.Disconnect((IProtocolToken)refuseToken2);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    BoltGlobalEvent.SendPrivateMessage("/kick <username>", new Color32(255, 0, 0, 255), ev.RaisedBy);
                }
                ev.Text = "";
            }
            if (cmd.StartsWith("/"))
            {
                ev.Text = "";
            }
            return(true);
        }
Ejemplo n.º 18
0
 public override void Connected(BoltConnection connection)
 {
     connection.SetCanReceiveEntities(false);
     if (CoopKick.IsBanned(connection.RemoteEndPoint.SteamId))
     {
         connection.Disconnect(new CoopKickToken
         {
             Banned = true,
             KickMessage = "Host banned you permanently from his games"
         });
     }
     else
     {
         CoopServerInfo.Instance.entity.Freeze(false);
     }
 }