public override void Handle(NecClient client, ChatMessage message, ChatResponse response,
                                    List <ChatResponse> responses)
        {
            if (client == null)
            {
                return;
            }

            if (message.message == null || message.message.Length <= 1)
            {
                return;
            }

            if (!message.message.StartsWith(CHAT_COMMAND_START))
            {
                return;
            }

            string commandMessage = message.message.Substring(1);

            string[] command = commandMessage.Split(CHAT_COMMAND_SEPARATOR);
            if (command.Length <= 0)
            {
                _Logger.Error(client, $"Command '{message.message}' is invalid");
                return;
            }

            string commandKey = command[0].ToLowerInvariant();

            if (!_commands.ContainsKey(commandKey))
            {
                _Logger.Error(client, $"Command '{commandKey}' does not exist");
                responses.Add(ChatResponse.CommandError(client, $"Command does not exist: {commandKey}"));
                return;
            }

            ChatCommand chatCommand = _commands[commandKey];

            if (client.account.state < chatCommand.accountState)
            {
                _Logger.Error(client,
                              $"Not entitled to execute command '{chatCommand.key}' (State < Required: {client.account.state} < {chatCommand.accountState})");
                return;
            }

            int cmdLength = command.Length - 1;

            string[] subCommand;
            if (cmdLength > 0)
            {
                subCommand = new string[cmdLength];
                Array.Copy(command, 1, subCommand, 0, cmdLength);
            }
            else
            {
                subCommand = new string[0];
            }

            chatCommand.Execute(subCommand, client, message, responses);
        }
Ejemplo n.º 2
0
        public void AddHandler(IHandler handler, bool overwrite = false)
        {
            if (overwrite)
            {
                if (_handlers.ContainsKey(handler.Id))
                {
                    _handlers[handler.Id] = handler;
                }
                else
                {
                    _handlers.Add(handler.Id, handler);
                }

                return;
            }

            if (_handlers.ContainsKey(handler.Id))
            {
                _logger.Error($"[{_identity}] HandlerId: {handler.Id} already exists");
            }
            else
            {
                _handlers.Add(handler.Id, handler);
            }
        }
Ejemplo n.º 3
0
        public override void Handle(NecConnection connection, NecPacket packet)
        {
            string accountName = packet.data.ReadCString();
            string password    = packet.data.ReadCString();
            string macAddress  = packet.data.ReadCString();
            int    unknown     = packet.data.ReadInt16();

            _Logger.Info($"Account:{accountName} Password:{password} Unknown:{unknown}");

            Account account = database.SelectAccountByName(accountName);

            if (account == null)
            {
                if (settings.requireRegistration)
                {
                    _Logger.Error(connection, $"AccountName: {accountName} doesn't exist");
                    SendResponse(connection, null);
                    connection.socket.Close();
                    return;
                }

                string bCryptHash = BCrypt.Net.BCrypt.HashPassword(password, NecSetting.B_CRYPT_WORK_FACTOR);
                account = database.CreateAccount(accountName, accountName, bCryptHash);
            }

            if (!BCrypt.Net.BCrypt.Verify(password, account.hash))
            {
                _Logger.Error(connection, $"Invalid password for AccountName: {accountName}");
                SendResponse(connection, null);
                connection.socket.Close();
                return;
            }

            NecClient client = new NecClient();

            client.account        = account;
            client.authConnection = connection;
            connection.client     = client;
            client.UpdateIdentity();
            server.clients.Add(client);

            SendResponse(connection, account);

            //if client did not send a hardbeat within 75 seconds, something went wrong. remove the client. Thats enough time for 4 heartbeats.
            Task.Delay(TimeSpan.FromSeconds(75)).ContinueWith
                (t1 =>
            {
                if (client != null)
                {
                    if (client.heartBeat == 0)
                    {
                        server.clients.Remove(client);
                        _Logger.Error($"Initial heartbeat missed. disconnecting client. Server.clientCount is now {server.clients.GetCount()}");
                    }
                }
            }
                );
        }
Ejemplo n.º 4
0
        public DropItem GetLoot(int monsterId)
        {
            monsterId = 40101; //   All monsters are beetles for now!!
            int       roll        = LootRoll();
            DropTable monsterDrop = dropTables.Find(x => x.MonsterId == monsterId);
            DropItem  dropItem    = null;

            if (monsterDrop != null)
            {
                List <DropTableItem> ItemDrop = monsterDrop.FindAll(roll);
                if (ItemDrop.Count == 1)
                {
                    Logger.Debug($"ItemId [ItemDrop ItemId {ItemDrop[0].ItemId}]");
                    if (!_server.SettingRepository.Items.TryGetValue(ItemDrop[0].ItemId, out ItemSetting itemSetting))
                    {
                        Logger.Error($"Could not retrieve ItemSettings for ItemId [{ItemDrop[0].ItemId}]");
                        return(null);
                    }

                    Logger.Debug($"ItemId [ItemDrop ItemId {ItemDrop[0].ItemId}]");
                    if (itemSetting.Id == 10200101)
                    {
                        itemSetting.IconType = 2;
                    }
                    else if (itemSetting.Id == 80000101)
                    {
                        itemSetting.IconType = 55;
                    }

                    Item item = _server.Instances64
                                .CreateInstance <Item>(); //  Need to get fully populated Item repository
                    item.AddItemSetting(itemSetting);
                    int numItems = GetNumberItems(ItemDrop[0].MinItems, ItemDrop[0].Maxitems + 1);
                    dropItem = new DropItem(numItems, item);
                }
            }
            else
            {
                if (!_server.SettingRepository.Items.TryGetValue(50100301, out ItemSetting itemSetting))
                {
                    Logger.Error($"Could not retrieve ItemSettings for default Item Camp");
                    return(null);
                }

                Item item = new Item(); //  Need to get fully populated Item repository
                item.IconType = 45;
                item.ItemType = 1;
                dropItem      = new DropItem(1, item);
            }

            return(dropItem);
        }
Ejemplo n.º 5
0
        public void StartCast()
        {
            if (_targetInstanceId == 0)
            {
                _targetInstanceId = _client.character.instanceId;
            }
            IInstance target = _server.instances.GetInstance(_targetInstanceId);

            switch (target) // ToDO     Do a hositilty check to make sure this is allowed
            {
            case NpcSpawn npcSpawn:
                _Logger.Debug($"Start casting Skill [{_skillId}] on NPCId: {npcSpawn.instanceId}");
                break;

            case MonsterSpawn monsterSpawn:
                _Logger.Debug($"Start casting Skill [{_skillId}] on MonsterId: {monsterSpawn.instanceId}");
                break;

            case Character character:
                _Logger.Debug($"Start casting Skill [{_skillId}] on CharacterId: {character.instanceId}");
                break;

            default:
                _Logger.Error(
                    $"Instance with InstanceId: {target.instanceId} does not exist.  the ground is gettin blasted");
                break;
            }

            if (!_server.settingRepository.skillBase.TryGetValue(_skillId, out SkillBaseSetting skillBaseSetting))
            {
                _Logger.Error($"Could not get SkillBaseSetting for skillId : {_skillId}");
                return;
            }

            float castTime = skillBaseSetting.castingTime;

            _Logger.Debug($"Start casting Skill [{_skillId}] cast time is [{castTime}]");
            RecvSkillStartCastR spell = new RecvSkillStartCastR(0, castTime);

            _server.router.Send(spell, _client);
            List <PacketResponse>                brList      = new List <PacketResponse>();
            RecvBattleReportStartNotify          brStart     = new RecvBattleReportStartNotify(_client.character.instanceId);
            RecvBattleReportEndNotify            brEnd       = new RecvBattleReportEndNotify();
            RecvBattleReportActionSkillStartCast brStartCast = new RecvBattleReportActionSkillStartCast(_skillId);

            brList.Add(brStart);
            brList.Add(brStartCast);
            brList.Add(brEnd);
            _server.router.Send(_client.map, brList);
        }
        /*public void SetHP(int modifier)
         * {
         *  lock (HpLock)
         *  {
         *      CurrentHp = modifier;
         *  }
         * }
         * public int GetHP()
         * {
         *  int hp;
         *  lock (HpLock)
         *  {
         *      hp = CurrentHp;
         *  }
         *  return hp;
         * }
         */
        public void UpdateHp(int modifier, NecServer server = null, bool verifyAgro = false, uint instanceId = 0)
        {
            hp.Modify(modifier);
            if (verifyAgro)
            {
                if (server == null)
                {
                    _Logger.Error("NecServer is null!");
                    return;
                }

                if (!GetAgroCharacter(instanceId))
                {
                    monsterAgroList.Add(instanceId, modifier);
                    Character character = (Character)server.instances.GetInstance(instanceId);
                    SetCurrentTarget(character);
                    SetAgro(true);
                    MonsterHate(server, true, instanceId);
                    SendBattlePoseStartNotify(server);
                    if (id == 4)
                    {
                        SetGotoDistance(1000);
                    }
                    else
                    {
                        SetGotoDistance(200);
                    }
                }
            }
        }
        public override void Handle(NecClient client, NecPacket packet)
        {
            int channelId = packet.Data.ReadInt32();

            if (channelId == -1)
            {
                Logger.Debug(
                    "Escape button was selected to close channel select. channelId code  == -0xFFFF => SendEventEnd");
                SendEventEnd(client);
                return;
            }

            if (!Server.Maps.TryGet(client.Character.MapId, out Map map))
            {
                Logger.Error($"MapId: {client.Character.MapId} does not exist");
                return;
            }

            client.Character.Channel = channelId;
            map.EnterForce(client);
            SendEventEnd(client);

            IBuffer res2 = BufferProvider.Provide();

            res2.WriteUInt32(client.Character.InstanceId);
            res2.WriteCString("IsThisMyChannel?????"); //Length to be Found
            Router.Send(Server.Clients.GetAll(), (ushort)AreaPacketId.recv_channel_notify, res2, ServerType.Area);
        }
Ejemplo n.º 8
0
        public override void Handle(NecClient client, NecPacket packet)
        {
            int data = packet.data.ReadInt32();

            _Logger.Error(client,
                          $"{client.soul.name} {client.character.name} has sent a disconnect packet to the server.  Wave GoodBye! ");

            IBuffer buffer = BufferProvider.Provide();

            buffer.WriteInt32(data);

            NecPacket response = new NecPacket(
                (ushort)CustomPacketId.RecvDisconnect,
                buffer,
                packet.serverType,
                PacketType.Disconnect
                );

            router.Send(client, response);

            Task.Delay(TimeSpan.FromSeconds(60)).ContinueWith
                (t1 =>
            {
                if (client == null)
                {
                    return;
                }
                clients.Remove(client);
            }
                );
        }
        public override void Execute(string[] command, NecClient client, ChatMessage message,
                                     List <ChatResponse> responses)
        {
            if (command[0] == null)
            {
                responses.Add(ChatResponse.CommandError(client, $"Invalid argument: {command[0]}"));
                return;
            }

            IBuffer res36 = BufferProvider.Provide();

            switch (command[0])
            {
            case "start":
                IBuffer res21 = BufferProvider.Provide();
                res21.WriteInt32(1);     // 0 = normal 1 = cinematic
                res21.WriteByte(0);
                router.Send(client, (ushort)AreaPacketId.recv_event_start, res21, ServerType.Area);

                IBuffer res22 = BufferProvider.Provide();

                res22.WriteCString(command[1]);                 // lable
                res22.WriteUInt32(client.character.instanceId); //newjp  ObjectId
                router.Send(client, (ushort)AreaPacketId.recv_event_script_play, res22, ServerType.Area);

                break;

            default:
                _Logger.Error($"There is no script of type : {command[1]} ");

                break;
            }
        }
Ejemplo n.º 10
0
        public override void Handle(NecConnection connection, NecPacket packet)
        {
            int accountId = packet.Data.ReadInt32();
            int unknown   = packet.Data.ReadInt32();

            byte[] unknown1 = packet.Data.ReadBytes(20); // Suspect SessionId

            // TODO replace with sessionId
            NecClient client = Server.Clients.GetByAccountId(accountId);

            if (client == null)
            {
                Logger.Error(connection, $"AccountId: {accountId} has no active session");
                connection.Socket.Close();
                return;
            }

            client.AreaConnection = connection;
            connection.Client     = client;

            IBuffer res = BufferProvider.Provide();

            res.WriteInt32(0); //  Error
            Router.Send(connection, (ushort)AreaPacketId.recv_base_enter_r, res);
        }
Ejemplo n.º 11
0
        public override void Execute(string[] command, NecClient client, ChatMessage message,
                                     List <ChatResponse> responses)
        {
            if (command[0] == null)
            {
                responses.Add(ChatResponse.CommandError(client,
                                                        $"Hi There!  Type /players world or /players map to see who's here.  You can also type a Character.Name"));
                return;
            }


            switch (command[0])
            {
            case "map":     //tells you all the people on the Map you're on
                foreach (NecClient theirClient in client.Map.ClientLookup.GetAll())
                {
                    //if(theirClient.Map.Id != -1 && theirClient.Character.InstanceId != 0)
                    responses.Add(ChatResponse.CommandError(client,
                                                            $"{theirClient.Character.Name} {theirClient.Soul.Name} is on Map {theirClient.Character.MapId} with InstanceID {theirClient.Character.InstanceId}"));
                }

                break;

            case "world":     //tells you all the people in the world
                foreach (NecClient theirClient in Server.Clients.GetAll())
                {
                    //if (theirClient.Map.Id != -1 && theirClient.Character.InstanceId != 0)
                    responses.Add(ChatResponse.CommandError(client,
                                                            $"{theirClient.Character.Name} {theirClient.Soul.Name} is on Map {theirClient.Character.MapId} with InstanceID {theirClient.Character.InstanceId}"));
                }

                break;


            default:     //you don't know what you're doing do you?
                bool soulFound = false;

                foreach (Character theirCharacter in Server.Characters.GetAll())
                {
                    Logger.Debug($"Comparing {theirCharacter.Name} to {command[0]}");
                    if (theirCharacter.Name == command[0])
                    {
                        responses.Add(ChatResponse.CommandError(client,
                                                                $"{theirCharacter.Name} {theirCharacter.SoulName} is on Map {theirCharacter.MapId} with InstanceID {theirCharacter.InstanceId}"));
                        soulFound = true;
                    }
                }

                if (soulFound == false)
                {
                    Logger.Error($"There is no command switch or player name matching : {command[0]} ");
                    responses.Add(
                        ChatResponse.CommandError(client, $"{command[0]} is not a valid players command."));
                }

                break;
            }
        }
Ejemplo n.º 12
0
        public override void Handle(NecClient client, NecPacket packet)
        {
            int       characterId = packet.data.ReadInt32();
            Character character   = database.SelectCharacterById(characterId);

            if (character == null)
            {
                _Logger.Error(client, $"No character for CharacterId: {characterId}");
                client.Close();
                return;
            }

            server.instances.AssignInstance(character);

            client.character = character;
            client.character.criminalState = client.soul.criminalLevel;
            client.UpdateIdentity();
            client.character.CreateTask(server, client);

            _Logger.Debug(client, $"Selected Character: {character.name}");

            IBuffer res3 = BufferProvider.Provide();

            res3.WriteInt32(0); //ERR-CHARSELECT error check
            res3.WriteUInt32(client.character.instanceId);

            //sub_4E4210_2341
            res3.WriteInt32(client.character.mapId);
            res3.WriteInt32(client.character.mapId);
            res3.WriteInt32(client.character.mapId);
            res3.WriteByte(0);
            res3.WriteByte(0);                                       //Bool
            res3.WriteFixedString(settings.dataAreaIpAddress, 0x41); //IP
            res3.WriteUInt16(settings.areaPort);                     //Port

            res3.WriteFloat(client.character.x);
            res3.WriteFloat(client.character.y);
            res3.WriteFloat(client.character.z);
            res3.WriteByte(client.character.heading);
            router.Send(client, (ushort)MsgPacketId.recv_chara_select_r, res3, ServerType.Msg);

            /*
             * ERR_CHARSELECT	GENERIC	Failed to select a character (CODE:<errcode>)
             * ERR_CHARSELECT	-8	Maintenance
             * ERR_CHARSELECT	-13	You have selected an illegal character
             */


            //Logic to support your dead body //Make this static.  need a predictable deadbody instance ID to support disconnect/reconnet
            DeadBody deadBody = new DeadBody();

            deadBody.id = character.id;
            server.instances.AssignInstance(deadBody);
            character.deadBodyInstanceId = deadBody.instanceId;
            deadBody.characterInstanceId = character.instanceId;
            _Logger.Debug($"Dead Body Instance ID {deadBody.instanceId}   |  Character Instance ID {character.instanceId}");
        }
Ejemplo n.º 13
0
        public override void Handle(NecConnection connection, NecPacket packet)
        {
            string accountName = packet.Data.ReadCString();
            string password    = packet.Data.ReadCString();
            string macAddress  = packet.Data.ReadCString();
            int    unknown     = packet.Data.ReadInt16();

            Logger.Info($"Account:{accountName} Password:{password} Unknown:{unknown}");

            Account account = Database.SelectAccountByName(accountName);

            if (account == null)
            {
                if (Settings.RequireRegistration)
                {
                    Logger.Error(connection, $"AccountName: {accountName} doesn't exist");
                    SendResponse(connection, null);
                    connection.Socket.Close();
                    return;
                }

                string bCryptHash = BCrypt.Net.BCrypt.HashPassword(password, NecSetting.BCryptWorkFactor);
                account = Database.CreateAccount(accountName, accountName, bCryptHash);
            }

            if (!BCrypt.Net.BCrypt.Verify(password, account.Hash))
            {
                Logger.Error(connection, $"Invalid password for AccountName: {accountName}");
                SendResponse(connection, null);
                connection.Socket.Close();
                return;
            }

            NecClient client = new NecClient();

            client.Account        = account;
            client.AuthConnection = connection;
            connection.Client     = client;
            client.UpdateIdentity();
            Server.Clients.Add(client);

            SendResponse(connection, account);
        }
Ejemplo n.º 14
0
        public byte[] Write(NecPacket packet, NecClient client)
        {
            // TODO update arrowgene service to write uint*

            byte[]  data     = packet.Data.GetAllBytes();
            IBuffer buffer   = BufferProvider.Provide();
            ulong   dataSize = (ushort)(data.Length + PacketIdSize);

            PacketLengthType packetLengthType;

            if (dataSize < byte.MaxValue)
            {
                packetLengthType = PacketLengthType.Byte;
                buffer.WriteByte((byte)packetLengthType);
                buffer.WriteByte((byte)dataSize);
            }
            else if (dataSize < ushort.MaxValue)
            {
                packetLengthType = PacketLengthType.UInt16;
                buffer.WriteByte((byte)packetLengthType);
                buffer.WriteInt16((ushort)dataSize);
            }
            else if (dataSize < uint.MaxValue)
            {
                packetLengthType = PacketLengthType.UInt32;
                buffer.WriteByte((byte)packetLengthType);
                buffer.WriteInt32((uint)dataSize);
            }
            else
            {
                _logger.Error($"{dataSize} to big");
                return(null);
            }

            buffer.WriteInt16(packet.Id);
            buffer.WriteBytes(data);

            byte headerSize = CalculateHeaderSize(packetLengthType);

            packet.Header = buffer.GetBytes(0, headerSize);

            return(buffer.GetAllBytes());
        }
Ejemplo n.º 15
0
 public Stealth(NecServer server, NecClient client, int skillId)
 {
     _server  = server;
     _client  = client;
     _skillid = skillId;
     if (!_server.SettingRepository.SkillBase.TryGetValue(skillId, out _skillSetting))
     {
         Logger.Error($"Could not get SkillBaseSetting for skillId : {skillId}");
     }
 }
Ejemplo n.º 16
0
        public override void Handle(NecClient client, NecPacket packet)
        {
            int skillId    = packet.data.ReadInt32(),
                skillLevel = packet.data.ReadInt32();
            //ToDo Add prerequisite checking for new skills
            //ToDo Add passive class specialty skills
            SkillTreeItem skillTreeItem = null;

            if (skillLevel > 1)
            {
                // Should already an entry for this skill
                skillTreeItem       = database.SelectSkillTreeItemByCharSkillId(client.character.id, skillId);
                skillTreeItem.level = skillLevel;
                if (database.UpdateSkillTreeItem(skillTreeItem) == false)
                {
                    _Logger.Error($"Updating SkillTreeItem for Character ID [{client.character.id}]");
                }
            }
            else
            {
                skillTreeItem         = new SkillTreeItem();
                skillTreeItem.skillId = skillId;
                skillTreeItem.level   = skillLevel;
                skillTreeItem.charId  = client.character.id;
                if (database.InsertSkillTreeItem(skillTreeItem) == false)
                {
                    _Logger.Error($"Adding SkillTreeItem for Character ID [{client.character.id}]");
                }
            }

            SendSkillTreeGain(client, skillId, skillLevel);
            client.character.skillPoints -= 1; //remove 1 skillpoint.  ToDo - ensure character has skill points
            RecvSelfSkillPointNotify recvSelfSkillPointNotify = new RecvSelfSkillPointNotify(client.character.skillPoints);

            router.Send(recvSelfSkillPointNotify, client);

            IBuffer res = BufferProvider.Provide();

            res.WriteInt32(0); //1 = failed to aquire skill, 0 = success? but no skill aquired
            router.Send(client, (ushort)AreaPacketId.recv_skill_request_gain_r, res, ServerType.Area);
        }
Ejemplo n.º 17
0
        public void AddHandler(IClientHandler clientHandler, bool overwrite = false)
        {
            if (overwrite)
            {
                if (_clientHandlers.ContainsKey(clientHandler.id))
                {
                    _clientHandlers[clientHandler.id] = clientHandler;
                }
                else
                {
                    _clientHandlers.Add(clientHandler.id, clientHandler);
                }

                return;
            }

            if (_clientHandlers.ContainsKey(clientHandler.id))
            {
                _Logger.Error($"[{_serverType}] ClientHandlerId: {clientHandler.id} already exists");
            }
            else
            {
                _clientHandlers.Add(clientHandler.id, clientHandler);
            }
        }
        public ChatMessage Deserialize(NecPacket packet)
        {
            int messageTypeValue = packet.Data.ReadInt32();

            if (!Enum.IsDefined(typeof(ChatMessageType), messageTypeValue))
            {
                Logger.Error($"ChatMessageType: {messageTypeValue} not defined");
                return(null);
            }

            ChatMessageType messageType = (ChatMessageType)messageTypeValue;
            string          recipient   = packet.Data.ReadCString();
            string          message     = packet.Data.ReadCString();

            return(new ChatMessage(messageType, recipient, message));
        }
        public ChatMessage Deserialize(NecPacket packet)
        {
            int messageTypeValue = packet.data.ReadInt32();

            if (!Enum.IsDefined(typeof(ChatMessageType), messageTypeValue))
            {
                _Logger.Error($"ChatMessageType: {messageTypeValue} not defined");
                return(null);
            }

            ChatMessageType messageType = (ChatMessageType)messageTypeValue;
            string          recipient   = packet.data.ReadCString();
            int             unknown     = packet.data.ReadInt32(); //Not sure what this is, it is new from JP client. Might be talk ring related.
            string          message     = packet.data.ReadCString();

            return(new ChatMessage(messageType, recipient, message));
        }
        public override void Handle(NecClient client, NecPacket packet)
        {
            IBuffer res = BufferProvider.Provide();


            Router.Send(client, (ushort)MsgPacketId.recv_base_login_r, res, ServerType.Msg);
            Union myUnion = Server.Instances.GetInstance((uint)client.Character.unionId) as Union;

            if (!Server.Database.DeleteUnion(myUnion.Id))
            {
                Logger.Error($"{myUnion.Name} could not be removed from the database");
                return;
            }

            Logger.Debug(
                $"{myUnion.Name} with Id {myUnion.Id} and instanceId {myUnion.InstanceId} removed and disbanded");
            client.Union = null;
        }
Ejemplo n.º 21
0
        public override void Handle(NecClient client, NecPacket packet)
        {
            client.Character.mapChange = false;
            int mapId = packet.Data.ReadInt32();
            Map map   = Server.Maps.Get(mapId);

            if (map == null)
            {
                Logger.Error(client, $"MapId: {mapId} not found in map lookup");
                client.Close();
                return;
            }
            map.Enter(client);
            IBuffer res = BufferProvider.Provide();

            res.WriteInt32(0);
            Router.Send(client, (ushort)AreaPacketId.recv_map_entry_r, res, ServerType.Area);
        }
        public override void Handle(NecClient client, NecPacket packet)
        {
            string soulPassword = packet.Data.ReadCString();
            Soul   soul         = client.Soul;

            soul.Password = soulPassword;
            if (!Database.UpdateSoul(soul))
            {
                Logger.Error(client, $"Failed to save password for SoulId: {soul.Id}");
                client.Close();
                return;
            }

            IBuffer res = BufferProvider.Provide();

            res.WriteInt32(0);
            res.WriteByte(0); // bool in JP client TODO what is it in US???
            Router.Send(client, (ushort)MsgPacketId.recv_soul_set_passwd_r, res, ServerType.Msg);
        }
Ejemplo n.º 23
0
        public override void Handle(NecClient client, NecPacket packet)
        {
            int data = packet.Data.ReadInt32();

            Logger.Error(client,
                         $"{client.Soul.Name} {client.Character.Name} has sent a disconnect packet to the server.  Wave GoodBye! ");

            IBuffer buffer = BufferProvider.Provide();

            buffer.WriteInt32(data);

            NecPacket response = new NecPacket(
                (ushort)CustomPacketId.RecvDisconnect,
                buffer,
                packet.ServerType,
                PacketType.Disconnect
                );

            Router.Send(client, response);
        }
Ejemplo n.º 24
0
        public override void Handle(NecClient client, NecPacket packet)
        {
            if (!server.maps.TryGet(client.character.mapId, out Map map))
            {
                _Logger.Error(client, $"No map found for MapId: {client.character.mapId}");
                client.Close();
                return;
            }

            int channelId = packet.data.ReadInt32();

            client.character.channel = channelId;

            IBuffer res = BufferProvider.Provide();

            res.WriteInt32(0); //Error Check

            //sub_4E4210_2341  // impacts map spawn ID (old Comment)
            res.WriteInt32(map.id);                                 //MapSerialID
            res.WriteInt32(channelId);                              //channel??????
            res.WriteFixedString(settings.dataAreaIpAddress, 0x41); //IP?
            res.WriteUInt16(settings.areaPort);                     //Port

            //sub_484420   //  does not impact map spawn coord (old Comment)
            res.WriteFloat(client.character.x);      //X Pos
            res.WriteFloat(client.character.y);      //Y Pos
            res.WriteFloat(client.character.z);      //Z Pos
            res.WriteByte(client.character.heading); //View offset
            //

            router.Send(client, (ushort)MsgPacketId.recv_channel_select_r, res, ServerType.Msg);

            map.EnterForce(client);
            SendEventEnd(client);

            IBuffer res2 = BufferProvider.Provide();

            res2.WriteUInt32(client.character.instanceId);
            res2.WriteCString("IsThisMyChannel?????"); //Length to be Found
            router.Send(server.clients.GetAll(), (ushort)AreaPacketId.recv_channel_notify, res2, ServerType.Area);
        }
Ejemplo n.º 25
0
        public void Send(NecPacket packet)
        {
            switch (packet.ServerType)
            {
            case ServerType.Area:
                AreaConnection.Send(packet);
                break;

            case ServerType.Msg:
                MsgConnection.Send(packet);
                break;

            case ServerType.Auth:
                AuthConnection.Send(packet);
                break;

            default:
                Logger.Error(this, "Invalid ServerType");
                break;
            }
        }
        public override void Handle(NecConnection connection, NecPacket packet)
        {
            int accountId = packet.data.ReadInt32();

            byte[] unknown = packet.data.ReadBytes(20); // Suspect SessionId
            // TODO replace with sessionId
            NecClient client = server.clients.GetByAccountId(accountId);

            if (client == null)
            {
                _Logger.Error(connection, $"AccountId: {accountId} has no active session");
                // TODO refactor null check
                SendResponse(connection, client);
                connection.socket.Close();
                return;
            }

            client.msgConnection = connection;
            connection.client    = client;
            SendResponse(connection, client);
        }
Ejemplo n.º 27
0
        private void Deliver(NecClient sender, ChatResponse chatResponse)
        {
            switch (chatResponse.MessageType)
            {
            case ChatMessageType.ChatCommand:
                chatResponse.Recipients.Add(sender);
                break;

            case ChatMessageType.All:
                chatResponse.Recipients.AddRange(sender.Map.ClientLookup.GetAll());
                break;

            case ChatMessageType.Area:
                chatResponse.Recipients.AddRange(sender.Map.ClientLookup.GetAll());
                break;

            case ChatMessageType.Shout:
                chatResponse.Recipients.AddRange(sender.Map.ClientLookup.GetAll());
                break;

            case ChatMessageType.Whisper:
                NecClient recipient = _server.Clients.GetBySoulName(chatResponse.RecipientSoulName);
                if (recipient == null)
                {
                    Logger.Error($"SoulName: {chatResponse.RecipientSoulName} not found");
                    return;
                }

                chatResponse.Recipients.Add(sender);
                chatResponse.Recipients.Add(recipient);
                break;

            default:
                chatResponse.Recipients.Add(sender);
                break;
            }

            _server.Router.Send(chatResponse);
        }
        public override void Handle(NecClient client, NecPacket packet)
        {
            string      soulName = packet.data.ReadCString();
            List <Soul> souls    = database.SelectSoulsByAccountId(client.account.id);

            foreach (Soul soul in souls)
            {
                if (soul.name == soulName)
                {
                    client.soul = soul;
                    break;
                }
            }

            IBuffer res = BufferProvider.Provide();

            if (client.soul == null)
            {
                _Logger.Error(client, $"Soul with name: '{soulName}' not found");
                res.WriteInt32(1); // 0 = OK | 1 = Failed to return to soul selection
                router.Send(client, (ushort)MsgPacketId.recv_soul_select_r, res, ServerType.Msg);
                client.Close();
                return;
            }

            res.WriteInt32(0); // 0 = OK | 1 = Failed to return to soul selection
            if (client.soul.password == null)
            {
                _Logger.Info(client, "Password not set, initiating set password");
                res.WriteByte(0); // bool - 0 = Set New Password | 1 = Enter Password
            }
            else
            {
                res.WriteByte(1); // bool - 0 = Set New Password | 1 = Enter Password
            }


            router.Send(client, (ushort)MsgPacketId.recv_soul_select_r, res, ServerType.Msg);
        }
Ejemplo n.º 29
0
        public override void Handle(NecClient client, NecPacket packet)
        {
            uint a    = packet.data.ReadUInt32();
            uint time = packet.data.ReadUInt32();

            client.heartBeat = time;
            //_Logger.Debug($"Time since client executable start in seconds {time/1000}");
            //_Logger.Debug($" if another heartbeat is not received in 600 seconds the client will be disconnected at {(time / 1000) + 600} : {DateTime.Now.AddSeconds(600)}");


            IBuffer buffer = BufferProvider.Provide();

            buffer.WriteInt32(0);
            buffer.WriteUInt32(time);

            NecPacket response = new NecPacket(
                (ushort)CustomPacketId.RecvHeartbeat2,
                buffer,
                packet.serverType,
                PacketType.HeartBeat2
                );

            router.Send(client, response);

            Task.Delay(TimeSpan.FromSeconds(600)).ContinueWith
                (t1 =>
            {
                if (client != null)
                {
                    if (client.heartBeat == time)
                    {
                        server.clients.Remove(client);
                        _Logger.Error($"Heartbeat missed. disconnecting client. Server.clientCount is now {server.clients.GetCount()}");
                    }
                }
            }
                );
        }
Ejemplo n.º 30
0
        public override void Handle(NecClient client, NecPacket packet)
        {
            int mapId     = packet.Data.ReadInt32();
            int channelId = packet.Data.ReadInt32();

            if (mapId == -2147483648)
            {
                Logger.Debug(
                    "Escape button was selected to close dungeun select. MapID code  == -2147483648 => SendEventEnd");
                SendEventEnd(client);
                return;
            }

            if (!Server.Maps.TryGet(mapId, out Map map))
            {
                Logger.Error($"MapId: {mapId} does not exist");
                return;
            }

            client.Character.Channel = channelId;
            map.EnterForce(client);
            SendEventEnd(client);
        }