Example #1
0
        internal void DisconnectAll()
        {
            if (Aardwolf != null)
            {
                Aardwolf.Disconnect();
                Aardwolf = null;
                World._OnConnected(false);
            }

            foreach (NetworkClient x in Clients)
            {
                x.Disconnect();
            }
            Clients.Clear();
        }
Example #2
0
        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);
        }