internal bool Update(long msTime) { if (Server != null && Server.Pending()) { NetworkClient c = new NetworkClient(Server.AcceptSocket(), this); Clients.Add(c); if (Program.Config.GetInt32("ClientCompression", 1) != 0) { c.Send(new[] { (byte)TelnetOpcodes.IAC, (byte)TelnetOpcodes.WILL, (byte)TelnetOpcodes.MCCP_V2, (byte)TelnetOpcodes.IAC, (byte)TelnetOpcodes.WILL, (byte)TelnetOpcodes.MCCP_V1 }); } if (Passwords.Count != 0) { c.Send(Encoding.Default.GetBytes("Proxy password?\n\r")); } else { c.AuthLevel = 1; c.OnAuthed(); } } bool r = World.Update(msTime); if (Aardwolf != null) { if (!Aardwolf.Receive()) { Aardwolf = null; World._OnConnected(false); } else { Aardwolf.Update(msTime); } } bool hadAuthedClient = false; for (int i = Clients.Count - 1; i >= 0; i--) { if (!Clients[i].Receive()) { Clients.RemoveAt(i); continue; } if (Clients[i].AuthLevel >= 1) { hadAuthedClient = true; } } if (Aardwolf == null && (hadAuthedClient || Program.Config.GetInt32("AutoConnect", 0) != 0)) { Log.Write("Connecting to " + Program.Config.GetString("MUD.Address", "aardmud.org") + ":" + Program.Config.GetInt32("MUD.Port", 4000).ToString()); try { TcpClient t = new TcpClient(Program.Config.GetString("MUD.Address", "aardmud.org"), Program.Config.GetInt32("MUD.Port", 4000)); Aardwolf = new NetworkAardwolf(t.Client, this); World._OnConnected(true); } catch (Exception e) { Log.Write("Failed connection to Aardwolf: " + e.Message); } } if (Aardwolf != null) { if (strMessage.Length > 0) { strMessage.SetLength(0); } foreach (Message m in World._MessageData) { if (m.Clients == null || !m.Clients.Contains((uint)0)) { continue; } if ((m.Flags & MessageFlags.GMCP) != MessageFlags.None) { if (m.MsgData == null || m.MsgData.Length == 0) { continue; } strMessage.Write(new byte[] { (byte)TelnetOpcodes.IAC, (byte)TelnetOpcodes.SB, (byte)TelnetOpcodes.GMCP }, 0, 3); strMessage.Write(m.MsgData, 0, m.MsgData.Length); strMessage.Write(new byte[] { (byte)TelnetOpcodes.IAC, (byte)TelnetOpcodes.SE }, 0, 2); } else { byte[] data = m.MsgData ?? Encoding.Default.GetBytes(m.Msg + m.LineEnding); strMessage.Write(data, 0, data.Length); } } if (strMessage.Length != 0) { Aardwolf.Send(strMessage.ToArray()); } } for (int i = Clients.Count - 1; i >= 0; i--) { if (strMessage.Length > 0) { strMessage.SetLength(0); } Clients[i].Update(msTime); if (Clients[i].AuthLevel < 1) { continue; } foreach (Message m in World._MessageData) { if (m.Clients != null && !m.Clients.Contains(Clients[i].Id)) { continue; } if ((m.AuthMask & ((ulong)1 << (Clients[i].AuthLevel - 1))) == 0) { continue; } //The problem is between here and next comment -- or at least this is what controls the GMCP shit that gets sent to the client. if ((m.Flags & MessageFlags.GMCP) != MessageFlags.None) { //the following line is the problem... looks like my client isnt registering "hasGMCPModule" // if(!Clients[i].HasGMCPModule(m.Msg.ToLower())) // continue; if (m.MsgData == null || m.MsgData.Length == 0) { continue; } strMessage.Write(new[] { (byte)TelnetOpcodes.IAC, (byte)TelnetOpcodes.SB, (byte)TelnetOpcodes.GMCP }, 0, 3); strMessage.Write(m.MsgData, 0, m.MsgData.Length); strMessage.Write(new[] { (byte)TelnetOpcodes.IAC, (byte)TelnetOpcodes.SE }, 0, 2); } else { string msg = m.Msg; msg = Colors.FixColors(msg, false, true); byte[] data = Encoding.Default.GetBytes(msg + m.LineEnding); strMessage.Write(data, 0, data.Length); } //BLAH*/ } if (strMessage.Length == 0) { continue; } Clients[i].Send(strMessage.ToArray()); } World._MessageData.Clear(); return(r); }
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); } } }