Exemplo n.º 1
0
        protected override void HandlePacket(TelnetPacket pkt)
        {
            base.HandlePacket(pkt);

            if (pkt.Type == TelnetOpcodes.GMCP && pkt.Header == TelnetOpcodes.SB && pkt.Data.Length > 0)
            {
                if (inStream.Length != 0)
                {
                    OnReceived(Encoding.Default.GetString(inStream.ToArray()), false);
                    inStream.SetLength(0);
                }
                Server.World._OnReceived(pkt.Data.ToArray());
                return;
            }

            if (pkt.Type == TelnetOpcodes.GMCP && pkt.Header == TelnetOpcodes.WILL)
            {
                Send(new[] { (byte)TelnetOpcodes.IAC, (byte)TelnetOpcodes.DO, (byte)TelnetOpcodes.GMCP });
                SendGMCP(Encoding.Default.GetBytes("Core.Hello { \"client\": \"ProxyMud\", \"version\": \"" + World.Version + "\" }"));
                {
                    if (Server.GMCPModules.Count > 0)
                    {
                        StringBuilder strModule = new StringBuilder();
                        foreach (KeyValuePair <string, int> x in Server.GMCPModules)
                        {
                            if (strModule.Length > 0)
                            {
                                strModule.Append(", ");
                            }
                            strModule.Append("\"" + x.Key + " " + x.Value.ToString() + "\"");
                        }
                        SendGMCP(Encoding.Default.GetBytes("Core.Supports.Set [ " + strModule.ToString() + " ]"));
                    }
                }
                return;
            }

            if (pkt.Type == TelnetOpcodes.TTYPE)
            {
                NetworkClient c = null;
                foreach (NetworkClient x in Server.Clients)
                {
                    if (x.AuthLevel >= 1 && (c == null || x.AuthLevel > c.AuthLevel))
                    {
                        c = x;
                    }
                }
                if (c != null)
                {
                    c.Send(pkt);
                }
                return;
            }

            if (pkt.Type == TelnetOpcodes.MCCP_V2)
            {
                if (pkt.Header == TelnetOpcodes.WILL)
                {
                    Send(new[] { (byte)TelnetOpcodes.IAC, (byte)TelnetOpcodes.DO, (byte)TelnetOpcodes.MCCP_V2 });
                }
                return;
            }

            if (pkt.Type == TelnetOpcodes.MCCP_V1)
            {
                if (pkt.Header == TelnetOpcodes.WILL)
                {
                    Send(new[] { (byte)TelnetOpcodes.IAC, (byte)TelnetOpcodes.DONT, (byte)TelnetOpcodes.MCCP_V1 });
                }
                return;
            }

            foreach (NetworkClient x in Server.Clients)
            {
                if (x.AuthLevel >= 1)
                {
                    x.Send(pkt);
                }
            }
        }