Example #1
0
        void HandleExtEntry(byte[] buffer, int offset)
        {
            string extName    = NetUtils.ReadString(buffer, offset + 1);
            int    extVersion = NetUtils.ReadI32(buffer, offset + 65);

            AddExtension(extName, extVersion);
            extensionCount--;
            CheckReadAllExtensions();
        }
Example #2
0
        void HandleLogin(byte[] packet)
        {
            LastAction = DateTime.UtcNow;
            if (loggedIn)
            {
                return;
            }
            byte version = packet[1];

            if (version != Server.version)
            {
                Leave(null, "Wrong version!", true); return;
            }

            name     = NetUtils.ReadString(packet, 2);
            skinName = name; DisplayName = name; truename = name;
            if (Server.ClassicubeAccountPlus)
            {
                name += "+";
            }

            string mppass = NetUtils.ReadString(packet, 66);

            if (PlayerConnecting != null)
            {
                PlayerConnecting(this, mppass);
            }
            OnPlayerConnectingEvent.Call(this, mppass);
            if (cancelconnecting)
            {
                cancelconnecting = false; return;
            }

            isDev = Server.Devs.CaselessContains(truename);
            isMod = Server.Mods.CaselessContains(truename);

            byte type = packet[130];

            Loading = true;
            if (disconnected)
            {
                return;
            }
            id = NextFreeId();

            if (type == 0x42)
            {
                hasCpe = true; SendCpeExtensions();
            }
            if (type != 0x42)
            {
                CompleteLoginProcess();
            }
        }
Example #3
0
        int HandleExtInfo(byte[] buffer, int offset, int left)
        {
            const int size = 1 + 64 + 2;

            if (left < size)
            {
                return(0);
            }

            appName        = NetUtils.ReadString(buffer, offset + 1);
            extensionCount = buffer[offset + 66];
            CheckReadAllExtensions(); // in case client supports 0 CPE packets
            return(size);
        }
Example #4
0
        void HandleLogin(byte[] buffer, int offset)
        {
            LastAction = DateTime.UtcNow;
            if (loggedIn)
            {
                return;
            }
            byte version = buffer[offset + 1];

            if (version != Server.version)
            {
                Leave(null, "Wrong version!", true); return;
            }

            name        = NetUtils.ReadString(buffer, offset + 2);
            SkinName    = name;
            DisplayName = name;
            truename    = name;
            if (Server.Config.ClassicubeAccountPlus)
            {
                name += "+";
            }

            string mppass = NetUtils.ReadString(buffer, offset + 66);

            OnPlayerStartConnectingEvent.Call(this, mppass);
            if (cancelconnecting)
            {
                cancelconnecting = false; return;
            }

            hasCpe  = buffer[offset + 130] == 0x42 && Server.Config.EnableCPE;
            level   = Server.mainLevel;
            Loading = true;
            if (Socket.Disconnected)
            {
                return;
            }

            if (hasCpe)
            {
                SendCpeExtensions();
            }
            else
            {
                CompleteLoginProcess();
            }
        }
Example #5
0
        void HandleLogin(byte[] buffer, int offset)
        {
            LastAction = DateTime.UtcNow;
            if (loggedIn)
            {
                return;
            }
            byte version = buffer[offset + 1];

            if (version != Server.version)
            {
                Leave(null, "Wrong version!", true); return;
            }

            name     = NetUtils.ReadString(buffer, offset + 2);
            SkinName = name; DisplayName = name; truename = name;
            if (ServerConfig.ClassicubeAccountPlus)
            {
                name += "+";
            }

            string mppass = NetUtils.ReadString(buffer, offset + 66);

            OnPlayerConnectingEvent.Call(this, mppass);
            if (cancelconnecting)
            {
                cancelconnecting = false; return;
            }

            byte protocolType = buffer[offset + 130];

            Loading = true;
            if (disconnected)
            {
                return;
            }

            if (protocolType == 0x42)
            {
                hasCpe = true; SendCpeExtensions();
            }
            if (protocolType != 0x42)
            {
                CompleteLoginProcess();
            }
        }
Example #6
0
        int HandleExtEntry(byte[] buffer, int offset, int left)
        {
            const int size = 1 + 64 + 4;

            if (left < size)
            {
                return(0);
            }

            string extName    = NetUtils.ReadString(buffer, offset + 1);
            int    extVersion = NetUtils.ReadI32(buffer, offset + 65);

            AddExtension(extName, extVersion);
            extensionCount--;
            CheckReadAllExtensions();
            return(size);
        }
Example #7
0
        void HandleChat(byte[] buffer, int offset)
        {
            if (!loggedIn)
            {
                return;
            }
            byte   continued = buffer[offset + 1];
            string text      = NetUtils.ReadString(buffer, offset + 2);

            LastAction = DateTime.UtcNow;
            if (FilterChat(ref text, continued))
            {
                return;
            }

            if (text != "/afk" && IsAfk)
            {
                CmdAfk.ToggleAfk(this, "");
            }

            // Typing //Command appears in chat as /command
            // Suggested by McMrCat
            if (text.StartsWith("//"))
            {
                text = text.Remove(0, 1);
            }
            else if (DoCommand(text))
            {
                return;
            }

            // People who are muted can't speak or vote
            if (muted)
            {
                SendMessage("You are muted."); return;
            }                                                     //Muted: Only allow commands

            // Lava Survival map vote recorder
            if (Server.lava.HasPlayer(this) && Server.lava.HasVote(text.ToLower()))
            {
                if (Server.lava.AddVote(this, text.ToLower()))
                {
                    SendMessage("Your vote for &5" + text.ToLower().Capitalize() + " %Shas been placed. Thanks!");
                    Server.lava.map.ChatLevelOps(name + " voted for &5" + text.ToLower().Capitalize() + "%S.");
                    return;
                }
                else
                {
                    SendMessage("&cYou already voted!");
                    return;
                }
            }
            // Filter out bad words
            if (ServerConfig.ProfanityFiltering)
            {
                text = ProfanityFilter.Parse(text);
            }

            if (IsHandledMessage(text))
            {
                return;
            }

            // Put this after vote collection so that people can vote even when chat is moderated
            if (Server.chatmod && !voice)
            {
                SendMessage("Chat moderation is on, you cannot speak."); return;
            }

            if (ChatModes.Handle(this, text))
            {
                return;
            }

            if (text[0] == ':' && PlayingTntWars)
            {
                string      newtext = text.Remove(0, 1).Trim();
                TntWarsGame it      = TntWarsGame.GameIn(this);
                if (it.GameMode == TntWarsGame.TntWarsGameMode.TDM)
                {
                    TntWarsGame.player pl = it.FindPlayer(this);
                    foreach (TntWarsGame.player p in it.Players)
                    {
                        if (pl.Red && p.Red)
                        {
                            SendMessage(p.p, "To Team " + Colors.red + "-" + color + name + Colors.red + "- %S" + newtext);
                        }
                        if (pl.Blue && p.Blue)
                        {
                            SendMessage(p.p, "To Team " + Colors.blue + "-" + color + name + Colors.blue + "- %S" + newtext);
                        }
                    }

                    Logger.Log(LogType.GameActivity, "[TNT Wars] [TeamChat (" + (pl.Red ? "Red" : "Blue") + ") " + name + " " + newtext);
                    return;
                }
            }

            text = HandleJoker(text);
            if (Chatroom != null)
            {
                Chat.MessageChatRoom(this, text, true, Chatroom); return;
            }

            bool   levelOnly = !level.SeesServerWideChat;
            string format    = levelOnly ? "<{0}>[level] {1}" : "<{0}> {1}";

            Logger.Log(LogType.PlayerChat, format, name, text);

            OnPlayerChatEvent.Call(this, text);
            if (cancelchat)
            {
                cancelchat = false; return;
            }

            if (levelOnly)
            {
                Chat.MessageLevel(this, text, true, level);
            }
            else
            {
                SendChatFrom(this, text);
            }
            CheckForMessageSpam();
        }
Example #8
0
 void HandleExtInfo(byte[] buffer, int offset)
 {
     appName        = NetUtils.ReadString(buffer, offset + 1);
     extensionCount = buffer[offset + 66];
     CheckReadAllExtensions(); // in case client supports 0 CPE packets
 }
Example #9
0
        void HandleChat(byte[] buffer, int offset)
        {
            if (!loggedIn)
            {
                return;
            }
            byte   continued = buffer[offset + 1];
            string text      = NetUtils.ReadString(buffer, offset + 2);

            LastAction = DateTime.UtcNow;
            if (FilterChat(ref text, continued))
            {
                return;
            }

            if (text != "/afk" && IsAfk)
            {
                CmdAfk.ToggleAfk(this, "");
            }

            // Typing //Command appears in chat as /command
            // Suggested by McMrCat
            if (text.StartsWith("//"))
            {
                text = text.Remove(0, 1);
            }
            else if (DoCommand(text))
            {
                return;
            }

            // People who are muted can't speak or vote
            if (muted)
            {
                Message("You are muted."); return;
            }                                                 //Muted: Only allow commands

            if (Server.voting)
            {
                if (CheckVote(text, this, "y", "yes", ref Server.YesVotes) ||
                    CheckVote(text, this, "n", "no", ref Server.NoVotes))
                {
                    return;
                }
            }

            if (LSGame.Instance.HandlesChatMessage(this, text))
            {
                return;
            }
            if (ZSGame.Instance.HandlesChatMessage(this, text))
            {
                return;
            }

            // Put this after vote collection so that people can vote even when chat is moderated
            if (Server.chatmod && !voice)
            {
                Message("Chat moderation is on, you cannot speak."); return;
            }

            // Filter out bad words
            if (ServerConfig.ProfanityFiltering)
            {
                text = ProfanityFilter.Parse(text);
            }

            if (ChatModes.Handle(this, text))
            {
                return;
            }
            text = HandleJoker(text);

            OnPlayerChatEvent.Call(this, text);
            if (cancelchat)
            {
                cancelchat = false; return;
            }

            if (Chatroom != null)
            {
                string roomPrefix = "<ChatRoom: " + Chatroom + "> λNICK: &f";
                Chat.MessageChat(ChatScope.Chatroom, this, roomPrefix + text, Chatroom, null);
            }
            else
            {
                Chat.MessageChat(this, "λFULL: &f" + text, null, true);
            }
        }
Example #10
0
        int HandleLogin(byte[] buffer, int offset, int left)
        {
            // protocol versions < 6 didn't have the usertype field,
            //  hence this two-packet-size-handling monstrosity
            const int old_size = 1 + 1 + 64 + 64;
            const int new_size = 1 + 1 + 64 + 64 + 1;

            // the packet must be at least old_size long
            if (left < old_size)
            {
                return(0);
            }

            LastAction      = DateTime.UtcNow;
            ProtocolVersion = buffer[offset + 1];

            // check size now that know whether usertype field is included or not
            int size = ProtocolVersion >= Server.VERSION_0020 ? new_size : old_size;

            if (left < size)
            {
                return(0);
            }
            if (loggedIn)
            {
                return(size);
            }

            name     = NetUtils.ReadString(buffer, offset + 2);
            SkinName = name; DisplayName = name; truename = name;

            if (ProtocolVersion > Server.VERSION_0030)
            {
                Leave(null, "Unsupported protocol version", true); return(-1);
            }
            if (name.Length < 1 || name.Length > 16)
            {
                Leave(null, "Usernames must be between 1 and 16 characters", true); return(-1);
            }
            if (!name.ContainsAllIn(USERNAME_ALPHABET))
            {
                Leave(null, "Invalid player name", true); return(-1);
            }

            if (Server.Config.ClassicubeAccountPlus)
            {
                name += "+";
            }
            string mppass = NetUtils.ReadString(buffer, offset + 66);

            OnPlayerStartConnectingEvent.Call(this, mppass);
            if (cancelconnecting)
            {
                cancelconnecting = false; return(size);
            }

            // usertype field has different meanings depending on protocol version
            //  Version 7 - 0x42 for CPE supporting client, should be 0 otherwise
            //  Version 6 - should be 0
            //  Version 5 - field does not exist
            if (ProtocolVersion >= Server.VERSION_0030)
            {
                hasCpe = buffer[offset + 130] == 0x42 && Server.Config.EnableCPE;
            }

            level   = Server.mainLevel;
            Loading = true;
            if (Socket.Disconnected)
            {
                return(size);
            }

            UpdateFallbackTable();
            if (hasCpe)
            {
                SendCpeExtensions();
            }
            else
            {
                CompleteLoginProcess();
            }
            return(size);
        }
Example #11
0
        void ProcessChat(byte[] buffer, int offset)
        {
            byte   continued = buffer[offset + 1];
            string text      = NetUtils.ReadString(buffer, offset + 2);

            LastAction = DateTime.UtcNow;
            if (FilterChat(ref text, continued))
            {
                return;
            }

            if (text != "/afk" && IsAfk)
            {
                CmdAfk.ToggleAfk(this, "");
            }

            bool isCommand;

            text = Chat.ParseInput(text, out isCommand);
            if (isCommand)
            {
                DoCommand(text); return;
            }

            // People who are muted can't speak or vote
            if (muted)
            {
                Message("You are muted."); return;
            }                                                 //Muted: Only allow commands

            if (Server.voting)
            {
                if (CheckVote(text, this, "y", "yes", ref Server.YesVotes) ||
                    CheckVote(text, this, "n", "no", ref Server.NoVotes))
                {
                    return;
                }
            }

            IGame game = IGame.GameOn(level);

            if (game != null && game.HandlesChatMessage(this, text))
            {
                return;
            }

            // Put this after vote collection so that people can vote even when chat is moderated
            if (!CheckCanSpeak("speak"))
            {
                return;
            }

            if (ChatModes.Handle(this, text))
            {
                return;
            }
            text = HandleJoker(text);

            OnPlayerChatEvent.Call(this, text);
            if (cancelchat)
            {
                cancelchat = false; return;
            }
            Chat.MessageChat(this, "λFULL: &f" + text, null, true);
        }
Example #12
0
 void HandleExtEntry(byte[] packet)
 {
     AddExtension(NetUtils.ReadString(packet, 1), NetUtils.ReadI32(packet, 65));
     extensionCount--;
     CheckReadAllExtensions();
 }
Example #13
0
 void HandleExtInfo(byte[] packet)
 {
     appName        = NetUtils.ReadString(packet, 1);
     extensionCount = packet[66];
     CheckReadAllExtensions(); // in case client supports 0 CPE packets
 }