예제 #1
0
        static void UploadStats(Client client, Packet msg)
        {
            try
            {
                if (!client.Connected)
                {
                    throw new Exception();
                }

                Stats stats = new Stats();
                stats.FromBytes(msg.Bytes, 0);

                User user = DataBase.GetUser(client.UserID).Value;

                // If new stats are newer, update
                if (stats.LastUpdated > user.Statistics.LastUpdated)
                {
                    user.Statistics = stats;
                }

                DataBase.SaveUser(user);
            }
            catch (Exception)
            {
                client.Send(new Packet(PacketCode.UploadStats, PacketInfo.Error));
            }
        }
예제 #2
0
        static void SignUp(Client client, Packet msg)
        {
            try
            {
                int index = 0;

                int nameLength = BitConverter.ToInt32(msg.Bytes, index);
                index += 4;
                string name = Encoding.UTF8.GetString(msg.Bytes, index, nameLength);
                index += nameLength;

                uint id;
                do
                {
                    id = (uint)random.Next(int.MinValue, int.MaxValue);
                }while (DataBase.ExistsUser(id));

                uint loginInfo = (uint)random.Next(int.MinValue, int.MaxValue);

                User user = new User(name, id, loginInfo);
                DataBase.SaveUser(user);

                client.LoggedIn = true;
                client.UserID   = id;

                List <byte> bytes = new List <byte>();
                bytes.AddRange(BitConverter.GetBytes(id));
                bytes.AddRange(BitConverter.GetBytes(loginInfo));

                client.Send(new Packet(PacketCode.SignUp, PacketInfo.Success, bytes.ToArray()));
            }
            catch (Exception)
            {
                client.Send(new Packet(PacketCode.SignUp, PacketInfo.Error));
            }
        }