public virtual void RemoveClient(EAClient client)
 {
     lock (Clients)
     {
         Clients.Remove(client);
     }
 }
 public virtual void AddClient(EAClient client)
 {
     lock (Clients)
     {
         Clients.Add(client);
     }
 }
Example #3
0
        public override void RemoveClient(EAClient client)
        {
            base.RemoveClient(client);

            //clean up this user's state.
            //are they logged in?
            var user = client.User;

            if (user != null)
            {
                Users.RemoveUser(user);

                var game = user.CurrentGame;
                var room = user.CurrentRoom;
                if (game != null)
                {
                    game.Users.RemoveUser(user);
                    user.CurrentGame = null;
                }

                if (room != null)
                {
                    room.Users.RemoveUser(user);
                    user.CurrentRoom = null;
                }
            }
        }
 private void RunLoop()
 {
     try
     {
         while (true)
         {
             //blocks til we get a new connection
             TcpClient client = Listener.AcceptTcpClient();
             if (client != null)
             {
                 var eaC = new EAClient(this, client);
                 eaC.SessionID = SessionID++;
                 AddClient(eaC);
             }
         }
     }
     catch
     {
         Console.WriteLine("A listener stopped working!");
     }
 }
Example #5
0
        public void TryLogin(DbAccount user, EAClient client)
        {
            //is someone else already logged in as this user?
            var oldUser = Users.GetUserByName(user.Username);

            if (oldUser != null)
            {
                oldUser.Connection.Close(); //should remove the old user.
                Thread.Sleep(500);
            }

            var personas = new string[4];

            for (int i = 0; i < user.Personas.Count; i++)
            {
                personas[i] = user.Personas[i];
            }

            //make a user object from DB user
            var user2 = new User()
            {
                Connection = client,
                ID         = user.ID,
                Personas   = personas,
                Username   = user.Username,
                IP         = client.IP
            };

            Users.AddUser(user2);
            client.User = user2;

            client.SendMessage(new AuthOut()
            {
                TOS      = user.ID.ToString(),
                NAME     = user.Username,
                PERSONAS = string.Join(',', user.Personas)
            });

            Rooms.SendRooms(user2);
        }
        public virtual void HandleMessage(string name, byte[] data, EAClient client)
        {
            try
            {
                var body = Encoding.ASCII.GetString(data);

                Type c;
                if (!NameToClass.TryGetValue(name, out c))
                {
                    Console.WriteLine("Unexpected Message Type " + name + ":");
                    Console.WriteLine(body);
                    return;
                }

                var msg = (AbstractMessage)Activator.CreateInstance(c);
                msg.Read(body);

                msg.Process(this, client);
            } catch (Exception)
            {
            }
        }