Exemplo n.º 1
0
        public static void PlayerMove(NetConnection connection, short dir)
        {
            var pData = Authentication.FindByConnection(connection);

            pData.Direction = dir;

            switch (dir)
            {
            case (int)Direction.Up:
                pData.PosY--;
                break;

            case (int)Direction.Down:
                pData.PosY++;
                break;

            case (int)Direction.Left:
                pData.PosX--;
                break;

            case (int)Direction.Right:
                pData.PosX++;
                break;
            }

            Maps.MapGeneral.Map.SendPlayerMove(pData, dir);

            LogConfig.WriteLog(pData.CharacterName + " Dir: " + dir + " X: " + pData.PosX + " Y: " + pData.PosY, System.Drawing.Color.Blue);
        }
Exemplo n.º 2
0
        public static void StartGame(NetConnection connection, byte slot)
        {
            var pData = Authentication.FindByConnection(connection);

            LogConfig.WriteLog($"GameServer Login Attempt: {pData.Account} {pData.IP}", System.Drawing.Color.Black);

            // limpa a memoria temporaria
            pData.Character = null;

            WorldServerPacket.SendGameServerData(connection, pData.HexID);

            // Carrega os dados do personagem
            Character_DB.Load(pData, slot);

            if (pData.GuildID > 0)
            {
                Guild.UpdatePlayerStatus(pData.GuildID, pData.CharacterID, true);
            }
            if (pData.GuildID > 0)
            {
                WorldServerPacket.SendGuildInfo(pData);
            }

            //Envia os dados de login para o game server numero 0
            GameServerPacket.Login(pData.HexID, 0);
        }
        /// <summary>
        /// Envia todos os dados para o WorldServer que selecionado pelo cliente.
        /// </summary>
        /// <param name="pIndex"></param>
        /// <param name="worldID"></param>
        public static void Login(string hexID, int worldID)
        {
            LoginServerPacket.HexID(hexID, hexID);

            var pData  = Authentication.FindByHexID(hexID);
            var buffer = WorldServerNetwork.WorldServer[worldID].Socket.CreateMessage();

            buffer.Write((int)PacketList.LoginServer_WorldServer_SendPlayerHexID);
            buffer.Write(pData.HexID);
            buffer.Write(pData.Account);
            buffer.Write(pData.ID);
            buffer.Write(pData.LanguageID);
            buffer.Write(pData.AccessLevel);
            buffer.Write(pData.Cash);
            buffer.Write(pData.Pin);

            //pega a quantidade de serviços
            var servicesID = pData.Service.ServicesID();

            buffer.Write(servicesID.Length);

            //escreve cada serviço no buffer
            foreach (var id in servicesID)
            {
                buffer.Write(pData.Service.ServiceTime(id));
            }

            WorldServerNetwork.WorldServer[worldID].SendData(buffer);

            LogConfig.WriteLog($"World Server {Settings.Server[worldID].Name} Login Attempt: {pData.Account} {pData.IP}");
            LogConfig.WriteLog($"World Server {Settings.Server[worldID].Name} Login Attempt: {pData.Account} {pData.IP}", System.Drawing.Color.Black);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Deleta um personagem pelo nome e slot.
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="slot"></param>
        public static void DeleteCharacter(NetConnection connection, int slot)
        {
            // Se a exclusão de personagem não estiver ativa, envia mensagem de erro
            if (!Settings.CharacterDelete)
            {
                WorldServerPacket.Message(connection, (int)PacketList.WorldServer_Client_CharacterDeleteDisabled);
                return;
            }

            var pData = Authentication.FindByConnection(connection);
            var level = Character_DB.GetLevel(pData.AccountID, slot);

            // Se o ocorrer algum erro, envia mensagem de erro
            // level -1, não encontrou dados do personagem
            if (level <= 0)
            {
                WorldServerPacket.Message(connection, (int)PacketList.Error);
                return;
            }

            // Se o level não estiver entre a faixa, envia mensagem de erro
            // não pode ser deletado
            if (level <Settings.CharacterDeleteMinLevel& level> Settings.CharacterDeleteMaxLevel)
            {
                WorldServerPacket.Message(connection, (int)PacketList.WorldServer_Client_InvalidLevelToDelete);
                return;
            }

            //Pega o nome do personagem e salva no log
            LogConfig.WriteLog($"Character Deleted: From: {pData.AccountID} {pData.Account} Char: {Character_DB.GetName(pData.AccountID, slot)}", System.Drawing.Color.Magenta);

            // Deleta o personagem
            Character_DB.Delete(pData.AccountID, slot);

            for (var n = 0; n < Constant.MAX_CHAR; n++)
            {
                pData.Character[n] = new Character()
                {
                    Name = string.Empty
                };

                //Carrega os personagens (preload)
                Character_DB.PreLoad(pData, n);
            }

            // Envia o PreLoad
            // pré carregamento do personagem, apenas informações básicas sprite, level, nome e classe (exibição na seleção de personagem).
            WorldServerPacket.PreLoad(pData);
            WorldServerPacket.Message(connection, (int)PacketList.WorldServer_Client_CharacterDeleted);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Disconenct
        /// </summary>
        /// <param name="username"></param>
        public static void PlayerDisconnect(string username)
        {
            if (!Authentication.IsConnected(username))
            {
                return;
            }

            var pData = Authentication.FindByAccount(username);

            //  LoginServerPacket.Message(Authentication.FindByAccount(pData.Username).HexID, (int)PacketList.Disconnect);

            pData.Connection.Disconnect("-");

            LogConfig.WriteLog($"Disconnected by login server: {username}", System.Drawing.Color.Black);

            ///temporario, precisa salvar o jogador antes
        }
Exemplo n.º 6
0
        public static void ReceiveData()
        {
            if (Socket == null)
            {
                return;
            }
            NetIncomingMessage msg;

            while ((msg = Socket.ReadMessage()) != null)
            {
                var pData = Authentication.FindByConnection(msg.SenderConnection);

                switch (msg.MessageType)
                {
                case NetIncomingMessageType.DiscoveryRequest:
                    string ip = msg.SenderEndPoint.Address.ToString();

                    Socket.SendDiscoveryResponse(null, msg.SenderEndPoint);

                    //   if (Program.ConnectForm.Logs.Checked == false)
                    //   {
                    //       Program.ConnectForm.WriteLog("Discovery Response IPEndPoint: " + msg.SenderEndPoint.Address, Color.Coral);
                    //   }
                    //   if (Settings.LogSystem == true) { LogConfig.WriteLog("Discovery Response IPEndPoint: " + msg.SenderEndPoint.Address); }

                    break;

                case NetIncomingMessageType.ErrorMessage:
                    #region ErrorMessage
                    var error = msg.ReadString();

                    //if (Program.ConnectForm.Logs.Checked == false)
                    //{
                    //     Program.ConnectForm.WriteLog("Error: " + error, Color.Coral);
                    //  }

                    // if (Settings.LogSystem == true) { LogConfig.WriteLog("Error: " + error); }
                    #endregion
                    break;

                case NetIncomingMessageType.StatusChanged:
                    #region StatusChanged : Connected
                    var status = (NetConnectionStatus)msg.ReadByte();

                    if (status == NetConnectionStatus.Connected)
                    {
                        LogConfig.WriteLog($"Status changed to connected: {msg.SenderEndPoint.Address}", System.Drawing.Color.Coral);
                        Authentication.Player.Add(new PlayerData(msg.SenderConnection, string.Empty, msg.SenderEndPoint.Address.ToString()));
                        GameServerPacket.NeedHexID(msg.SenderConnection);
                    }
                    #endregion

                    #region StatusChanged : Disconnected
                    if (status == NetConnectionStatus.Disconnected)
                    {
                        LogConfig.WriteLog($"ID: {pData.CharacterID} {pData.CharacterName} Status changed to disconnected: " + msg.SenderEndPoint.Address, System.Drawing.Color.Coral);
                        MySQL.Character_DB.Save(pData);
                        pData.Clear();
                        Authentication.Player.Remove(pData);
                    }
                    #endregion
                    break;

                case NetIncomingMessageType.Data:
                    GameServerData.HandleData(pData.Connection, msg);
                    break;


                default:
                    //  if (Settings.LogSystem == true) { LogConfig.WriteLog("Unhandled type: " + msg.MessageType); }

                    //  Program.ConnectForm.WriteLog("Unhandled type: " + msg.MessageType, Color.DarkRed);
                    break;
                }

                Socket.Recycle(msg);
            }
        }
        /// <summary>
        /// Recebe os dados.
        /// </summary>
        public static void ReceivedData()
        {
            NetIncomingMessage msg;

            while ((msg = Socket.ReadMessage()) != null)
            {
                var pData = Authentication.FindByConnection(msg.SenderConnection);

                switch (msg.MessageType)
                {
                case NetIncomingMessageType.DiscoveryRequest:
                    Socket.SendDiscoveryResponse(null, msg.SenderEndPoint);
                    LogConfig.WriteLog($"Discovery Response IPEndPoint: {msg.SenderEndPoint.Address}", Color.Coral);

                    break;

                case NetIncomingMessageType.ErrorMessage:
                    #region ErrorMessage
                    var error = msg.ReadString();

                    LogConfig.WriteLog($"Error: {error}", Color.Coral);

                    #endregion

                    break;

                case NetIncomingMessageType.StatusChanged:

                    #region StatusChanged : Connected
                    NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte();
                    if (status == NetConnectionStatus.Connected)
                    {
                        LogConfig.WriteLog($"Status changed to connected: {msg.SenderEndPoint.Address}", Color.Coral);
                        Authentication.Player.Add(new PlayerData(msg.SenderConnection, string.Empty, msg.SenderEndPoint.Address.ToString()));
                        WorldServerPacket.NeedHexID(msg.SenderConnection);
                    }
                    #endregion

                    #region StatusChanged : Disconnected
                    if (status == NetConnectionStatus.Disconnected)
                    {
                        pData = Authentication.FindByConnection(msg.SenderConnection);

                        LogConfig.WriteLog($"Status changed to disconnected: {pData.AccountID} {pData?.Account} {msg.SenderEndPoint.Address} {pData.HexID}", Color.Coral);

                        pData.Clear();
                        Authentication.Player.Remove(pData);
                    }
                    #endregion

                    break;

                case NetIncomingMessageType.Data:
                    WorldServerData.HandleData(pData.Connection, msg);
                    break;

                default:
                    if (Settings.LogSystem)
                    {
                        LogConfig.WriteLog($"Unhandled type: {msg.MessageType}");
                    }

                    Program.WorldForm.WriteLog($"Unhandled type: {msg.MessageType}", Color.DarkRed);
                    break;
                }

                Socket.Recycle(msg);
            }
        }
        /// <summary>
        /// Recebe os dados dos clientes.
        /// </summary>
        public static void ReceivedData()
        {
            NetIncomingMessage msg;

            while ((msg = Socket.ReadMessage()) != null)
            {
                var pData = Authentication.FindByConnection(msg.SenderConnection);

                switch (msg.MessageType)
                {
                case NetIncomingMessageType.DiscoveryRequest:
                    #region Find Banned IP
                    if (Accounts_DB.BannedIP(msg.SenderEndPoint.Address.ToString()) == true)
                    {
                        LogConfig.WriteLog("Warning: Attempted IP Banned " + msg.SenderEndPoint.Address);
                        LogConfig.WriteLog("Warning: Attempted IP Banned " + msg.SenderEndPoint.Address, Color.Coral);
                        return;
                    }
                    #endregion

                    LoginServerNetwork.Socket.SendDiscoveryResponse(null, msg.SenderEndPoint);
                    LogConfig.WriteLog($"Discovery Response IPEndPoint: {msg.SenderEndPoint.Address}", Color.Coral);
                    break;

                case NetIncomingMessageType.ErrorMessage:
                    LogConfig.WriteLog($"Error: {msg.ReadString()}", Color.Coral);
                    break;

                case NetIncomingMessageType.StatusChanged:
                    #region Status Changed Connected
                    NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte();

                    if (status == NetConnectionStatus.Connected)
                    {
                        LogConfig.WriteLog($"Status changed to connected: {msg.SenderEndPoint.Address}", Color.Coral);
                        Authentication.Player.Add(new PlayerData(msg.SenderConnection, NetUtility.ToHexString(msg.SenderConnection.RemoteUniqueIdentifier), msg.SenderEndPoint.Address.ToString()));
                    }
                    #endregion

                    #region Status Changed Disconnected
                    if (status == NetConnectionStatus.Disconnected)
                    {
                        pData = Authentication.FindByHexID(NetUtility.ToHexString(msg.SenderConnection.RemoteUniqueIdentifier));

                        //1 - enabled, 0 - disabled
                        if (Settings.LogSystem == 1)
                        {
                            LogConfig.WriteLog($"Status changed to disconnected: {pData?.ID} {pData?.Account} {msg.SenderEndPoint.Address} {pData.HexID}");
                        }
                        if (!Settings.LogSystemScreen)
                        {
                            LogConfig.WriteLog($"Status changed to disconnected: {pData?.ID} {pData?.Account} {msg.SenderEndPoint.Address} {pData.HexID}", Color.Coral);
                        }

                        Accounts_DB.UpdateLastIP(pData.Account, pData.IP);
                        Accounts_DB.UpdateLoggedIn(pData.Account, 0);     //0 disconnect
                        Accounts_DB.UpdateCurrentIP(pData.Account, "");

                        Authentication.Player.Remove(pData);
                    }
                    #endregion
                    break;

                case NetIncomingMessageType.Data:
                    LoginServerData.HandleData(pData.HexID, msg);
                    break;

                default:
                    //Registra qualquer mensagem invalida
                    LogConfig.WriteLog($"Unhandled type: {msg.MessageType}", Color.DarkRed);
                    break;
                }

                LoginServerNetwork.Socket.Recycle(msg);
            }
        }