private void ClientDataReceived(object sender, SimpleClient.DataReceivedEventArgs e)
        {
            try
            {
                var messageDataReader = new BigEndianReader(e.Data.Data);

                NetworkMessage message = MessageReceiver.BuildMessage((uint)e.Data.MessageId.Value, messageDataReader);

                SaveMsg(message, ConnectionDestination.Client);
                if (ClientMessageReceived != null)
                {
                    OnClientMessageReceived(new MessageReceivedEventArgs(message));
                }

                if (message == null)
                {
                    Send(e.Data, ConnectionDestination.Server);
                    return;
                }


                // here


                if (!message.Cancel)
                {
                    Send(e.Data, ConnectionDestination.Server);
                    messageDataReader.Dispose();
                    message = null;
                }
            }
            catch (Exception ex)
            {
                if (Client != null && WindowManager.MainWindow.Logger != null)
                {
                    WindowManager.MainWindow.Logger.Error("[Network] ClientDataReceived Function -> " + ex.Message);
                }
                else
                {
                    WindowManager.MainWindow.Logger.Error("[Network] ClientDataReceived Function -> " + ex.Message);
                }
            }
        }
Esempio n. 2
0
        private void OnClientDataReceived(object sender, SimpleClient.DataReceivedEventArgs e)
        {
            BigEndianReader bigEndianReader = new BigEndianReader(e.Data.Data);
            NetworkMessage  msg             = MessageReceiver.BuildMessage((uint)e.Data.MessageId.Value, (IDataReader)bigEndianReader);

            if (msg == null)
            {
                this.Send(e.Data, NetworkDestinationEnum.Server);
            }
            else
            {
                if (this.Game)
                {
                    if (msg.MessageId == 110U)
                    {
                        AuthenticationTicketMessage authenticationTicketMessage = (AuthenticationTicketMessage)msg;
                        TicketEntry ticket = TicketsManager.GetTicket();
                        if (ticket.Address == "" || ticket.Port == (ushort)0)
                        {
                            return;
                        }
                        this.Ticket = authenticationTicketMessage.Ticket;
                        this.Lang   = authenticationTicketMessage.Lang;
                        this.Server.Start(ticket.Address, (short)ticket.Port);
                        this.Instance = ticket.Instance;
                        this.Window   = ticket.Window;
                        this.Window.UpdateClient(this);
                    }
                    else
                    {
                        this.Send(e.Data, NetworkDestinationEnum.Server);
                    }
                }
                else
                {
                    this.Send(e.Data, NetworkDestinationEnum.Server);
                }
                this.OnMessageSent(new SyncClient.MessageSentEventArgs(msg, e.Data));
            }
        }
Esempio n. 3
0
        private void OnServerDataReceived(object sender, SimpleClient.DataReceivedEventArgs e)
        {
            BigEndianReader bigEndianReader = new BigEndianReader(e.Data.Data);
            NetworkMessage  msg             = MessageReceiver.BuildMessage((uint)e.Data.MessageId.Value, (IDataReader)bigEndianReader);

            if (msg == null)
            {
                this.Send(e.Data, NetworkDestinationEnum.Client);
            }
            else
            {
                switch (msg.MessageId)
                {
                case 1:
                    if (!this.Game)
                    {
                        this.Send(e.Data, NetworkDestinationEnum.Client);
                        this.Window      = new UserForm(this);
                        this.Window.Text = "Nouveau client";
                        WindowManager.AddChildrenForm((Form)this.Window);
                        break;
                    }
                    break;

                case 22:
                    this.Window.Text = ((IdentificationSuccessMessage)msg).Login;
                    this.Send(e.Data, NetworkDestinationEnum.Client);
                    break;

                case 42:
                    SelectedServerDataMessage serverDataMessage = (SelectedServerDataMessage)msg;
                    TicketsManager.RegisterTicket(serverDataMessage.Address, (ushort)serverDataMessage.Ports[0], this.Instance, this.Window);
                    this.Send((NetworkMessage) new SelectedServerDataMessage(serverDataMessage.ServerId, "127.0.0.1", Configuration.GamePort, serverDataMessage.CanCreateNewCharacter, serverDataMessage.Ticket), NetworkDestinationEnum.Client);
                    this.Register = true;
                    break;

                case 101:
                    this.Send((NetworkMessage) new AuthenticationTicketMessage(this.Lang, this.Ticket), NetworkDestinationEnum.Server);
                    break;

                case 153:
                    CharacterSelectedSuccessMessage selectedSuccessMessage = (CharacterSelectedSuccessMessage)msg;
                    UserForm window = this.Window;
                    window.Text = window.Text + " (" + selectedSuccessMessage.Infos.Name + ")";
                    this.Send(e.Data, NetworkDestinationEnum.Client);
                    break;

                case 6253:
                    this.RDM = ((RawDataMessage)msg).Content;
                    this.Window.Button_SaveRDM.Enabled = true;
                    this.Send(e.Data, NetworkDestinationEnum.Client);
                    break;

                case 6469:
                    SelectedServerDataExtendedMessage dataExtendedMessage = (SelectedServerDataExtendedMessage)msg;
                    TicketsManager.RegisterTicket(dataExtendedMessage.Address, (ushort)dataExtendedMessage.Ports[0], this.Instance, this.Window);
                    this.Send((NetworkMessage) new SelectedServerDataExtendedMessage(dataExtendedMessage.ServerId, "127.0.0.1", Configuration.GamePort, dataExtendedMessage.CanCreateNewCharacter, dataExtendedMessage.Ticket, dataExtendedMessage.Servers), NetworkDestinationEnum.Client);
                    this.Register = true;
                    break;

                default:
                    this.Send(e.Data, NetworkDestinationEnum.Client);
                    break;
                }
                this.OnMessageReceived(new SyncClient.MessageReceivedEventArgs(msg, e.Data));
            }
        }
        private void ServerDataReceived(object sender, SimpleClient.DataReceivedEventArgs e)
        {
            try
            {
                var messageDataReader = new BigEndianReader(e.Data.Data);

                NetworkMessage message = MessageReceiver.BuildMessage((uint)e.Data.MessageId.Value, messageDataReader);

                SaveMsg(message, ConnectionDestination.Server);
                if (ServerMessageReceived != null)
                {
                    OnServerMessageReceived(new MessageReceivedEventArgs(message));
                }

                if (message == null)
                {
                    Send(e.Data, ConnectionDestination.Client);
                    return;
                }

                // here

                if (message.MessageId == 6469 || message.MessageId == 42)
                {
                    SelectedServerDataMessage msg = (SelectedServerDataMessage)message;
                    TicketsManager.RegisterTicket(Client.AccountName, Client.Network.Instance, msg);

                    ((ClientNetwork)Client.Network).Ticket = true;
                    Client.Network.Send(new SelectedServerDataMessage(msg.serverId, "127.0.0.1", new uint[] { 443 }, msg.canCreateNewCharacter, msg.ticket), ConnectionDestination.Client);
                    message.Cancel = true;
                    Client.UnloadClient();
                }

                if (message.MessageId == 22)
                {
                    IdentificationSuccessMessage msg = (IdentificationSuccessMessage)message;
                    Client.AccountName = msg.login;
                }

                if (message.MessageId == 153)
                {
                    CharacterSelectedSuccessMessage msg = (CharacterSelectedSuccessMessage)message;

                    Client.Dock.Invoke((MethodInvoker) delegate
                    {
                        Client.Dock.Text = msg.infos.name + " (" + Client.AccountName + ")";
                    });
                }

                if (!message.Cancel)
                {
                    Send(e.Data, ConnectionDestination.Client);
                    messageDataReader.Dispose();
                    message = null;
                }
            }
            catch (Exception ex)
            {
                if (Client != null && WindowManager.MainWindow.Logger != null)
                {
                    WindowManager.MainWindow.Logger.Error("[Network] ServerDataReceived Function -> " + ex.Message);
                }
            }
        }