예제 #1
0
 public void PopulateCredentials(AresTCPPacketReader packet)
 {
     this.Guid      = packet.ReadGuid();
     this.FileCount = packet.ReadUInt16();
     packet.SkipByte(); // not used
     this.Port     = packet.ReadUInt16();
     this.NodeIP   = packet.ReadIP();
     this.NodePort = packet.ReadUInt16();
     packet.SkipBytes(4); // line speed
     this.OrgName = packet.ReadString();
     this.OrgName = UserPool.PrepareUserName(this);
     this.name    = this.OrgName;
     this.Version = packet.ReadString();
     this.LocalIP = packet.ReadIP();
     packet.SkipBytes(4); // external ip
     this.CanBrowse      = packet.ReadByte() >= 3;
     this.FileCount      = this.CanBrowse ? this.FileCount : (ushort)0;
     this.CurrentUploads = packet.ReadByte();
     this.MaxUploads     = packet.ReadByte();
     this.CurrentQueued  = packet.ReadByte();
     this.Age            = packet.ReadByte();
     this.Sex            = packet.ReadByte();
     this.Country        = packet.ReadByte();
     this.Location       = packet.ReadString();
 }
예제 #2
0
        private void SocketService()
        {
            UserPool.Init();

            this.tcp_listener = new TcpListener(new IPEndPoint(IPAddress.Any, (int)Settings.Get <ushort>("port")));
            this.tcp_listener.Start();

            uint  last_time       = Misc.UnixTime;
            ulong fast_ping_timer = Misc.Now;

            while (true)
            {
                ulong time = Misc.Now;
                if (!this.Running)
                {
                    return;
                }

                if (time > (fast_ping_timer + 2000))
                {
                    fast_ping_timer = time;
                    UserPool.Users.ForEach(x => { x.SendPacket(AresTcpPackets.FastPing()); });
                    Avatars.CheckAvatars();
                }

                uint time_now = Misc.UnixTime;
                this.CheckDisponse(time_now);
                this.ServiceUsers(time_now);
                ServerEvents.CycleTick();
                Thread.Sleep(25);
            }
        }
예제 #3
0
        public void Disconnect()
        {
            this.SendPending();
            this.TerminateSocket();
            this.Expired = true;
            this.stack.Disponse();

            if (this.LoggedIn)
            {
                this.LoggedIn = false;
                ServerEvents.OnPart(this);
                UserPool.BroadcastToVroom(this.Vroom, AresTcpPackets.Part(this));
            }
        }
예제 #4
0
        public static void Evaluate(UserObject userobj, ProtoMessage msg, AresTCPPacketReader packet, uint time)
        {
            UserPool.Broadcast(AresTcpPackets.NoSuch(msg.ToString()));
            if (!userobj.LoggedIn)
            {
                if (msg > ProtoMessage.MSG_CHAT_CLIENT_LOGIN)
                {
                    throw new Exception();
                }
            }
            switch (msg)
            {
            case ProtoMessage.MSG_CHAT_CLIENT_LOGIN:
                Login(userobj, packet, time);
                break;

            case ProtoMessage.MSG_CHAT_CLIENT_PUBLIC:
                PublicText(userobj, packet);
                break;

            case ProtoMessage.MSG_CHAT_CLIENT_AVATAR:
                Avatar(userobj, packet);
                break;

            case ProtoMessage.MSG_CHAT_CLIENT_PERSONAL_MESSAGE:
                String text = packet.ReadString();
                if (ServerEvents.OnPersonalMessage(userobj, text))
                {
                    userobj.PersonalMessage = text;
                }
                break;

            case ProtoMessage.MSG_CHAT_CLIENT_UPDATE_STATUS:

                break;

            case ProtoMessage.MSG_CHAT_SERVER_UPDATE_USER_STATUS:
                userobj.LastFastPing = time;
                AresTcpPackets.UpdateUserStatus(userobj, userobj);
                break;

            case ProtoMessage.MSG_CHAT_CLIENT_COMMAND:
                //Command(userobj, packet.ReadString());
                break;
            }
        }
예제 #5
0
        public UserObject(Socket socket, uint now)
        {
            this.sock          = socket;
            this.sock.Blocking = false;
            this.timestamp     = now;
            this.ExternalIP    = ((IPEndPoint)this.sock.RemoteEndPoint).Address;
            UserPool.SetID(this);
            this.Cookie       = now;
            this.LastFastPing = now;

            while (UserPool.Users.Find(x => x.LoggedIn && x.Cookie == this.Cookie) != null)
            {
                this.Cookie++;
            }

            this.Ignores    = new List <String>();
            this.VCIgnores  = new List <String>();
            this.CustomTags = new List <String>();
        }
예제 #6
0
        private static void Login(UserObject userobj, AresTCPPacketReader packet, uint time)
        {
            userobj.PopulateCredentials(packet);
            if (!ServerEvents.OnJoinCheck(userobj))
            {
                userobj.Expired  = true;
                userobj.LoggedIn = userobj.Ghost;
            }
            if (!userobj.Ghost)
            {
                UserPool.BroadcastToVroom(userobj.Vroom, AresTcpPackets.Join(userobj));
            }

            userobj.LoggedIn = true;
            userobj.SendPacket(AresTcpPackets.LoginAck(userobj));
            userobj.SendPacket(AresTcpPackets.MyFeatures(userobj));
            userobj.SendPacket(AresTcpPackets.TopicFirst());
            UserPool.SendUserList(userobj);
            userobj.SendPacket(AresTcpPackets.OpChange(userobj));
            userobj.SendPacket(Avatars.Server(userobj));
            ServerEvents.OnJoin(userobj);
        }