Beispiel #1
0
        public static void Handle(Packet packet)
        {
            var createCharPacket = new CreateCharPacket(packet);

            if (packet.Sender.User == null)
            {
                packet.Sender.KillConnection("Session Invalid.");
                return;
            }

            var nameTaken = CharacterModel.CheckNameExists(LobbyServer.Instance.Database.Connection,
                                                           createCharPacket.CharacterName);

            if (nameTaken)
            {
                packet.Sender.SendError("Character name taken!");
                return;
            }

            if (createCharPacket.CarType != 95 || createCharPacket.Color != 16777218)
            {
                Log.Error("Client {0} sent invalid car data!", packet.Sender.EndPoint.Address.ToString());
                packet.Sender.SendError("Invalid car.");
                return;
            }

            var character = new Character()
            {
                Uid       = packet.Sender.User.Id,
                Name      = createCharPacket.CharacterName,
                Avatar    = createCharPacket.Avatar,
                MitoMoney = LobbyServer.Instance.Config.Lobby.NewCharacterMito,
                Hancoin   = LobbyServer.Instance.Config.Lobby.NewCharacterHancoin
            };

            CharacterModel.CreateCharacter(LobbyServer.Instance.Database.Connection, ref character);

            character.ActiveVehicleId = (uint)VehicleModel.Create(LobbyServer.Instance.Database.Connection, new Vehicle()
            {
                CarType = createCharPacket.CarType,
                Color   = createCharPacket.Color,
            }, character.Id);
            CharacterModel.Update(LobbyServer.Instance.Database.Connection, character);

            packet.Sender.Send(new CreateCharAnswerPacket
            {
                CharacterName   = createCharPacket.CharacterName,
                CharacterId     = character.Id,
                ActiveVehicleId = (int)character.ActiveVehicleId,
            }.CreatePacket());
        }
Beispiel #2
0
        public static void CreateCharacter(Packet packet)
        {
            string characterName = packet.Reader.ReadUnicode();
            ulong  UIDCreate     = packet.Reader.ReadUInt64();
            ulong  Avatar        = 1;

            //  ulong Avatar = packet.Reader.ReadUInt64();
            CharacterModel.CreateCharacter(LobbyServer.Instance.Database.Connection, packet.Sender.User.UID, characterName, Avatar);



            // TODO: Verify, Handle

            var ack = new Packet(83);

            ack.Writer.WriteUnicodeStatic(characterName, 21);
            ack.Writer.Write(UIDCreate);
            //  ack.Writer.Write(Avatar);
            packet.Sender.Send(ack);
            packet.Sender.Error("Create Character Success Name: {0}", characterName);
        }
Beispiel #3
0
        public static void Test_RetrieveChar()
        {
            var uid       = AccountModel.CreateAccount(DbConnection.Connection, "127.0.0.1", "admin", "admin");
            var character = new Character
            {
                Uid    = (ulong)uid,
                Name   = "GigaToni",
                Avatar = 1,
            };

            CharacterModel.CreateCharacter(DbConnection.Connection, ref character);
            character.ActiveVehicleId = (uint)VehicleModel.Create(DbConnection.Connection, new Vehicle()
            {
                CarType = 1,
                Color   = 0,
            }, character.Id);
            CharacterModel.Update(DbConnection.Connection, character);

            character = null;
            character = CharacterModel.Retrieve(DbConnection.Connection, "GigaToni");
            Assert.IsNotNull(character);
            Console.WriteLine(character.Name);
        }