Ejemplo n.º 1
0
        public GameServer()
        {
            Connection.PacketReceived += (obj, eventArgs) =>
            {
                if (Enum.IsDefined(typeof(InComingPacket), eventArgs.Type))
                {
                    var incomingPacketType = (InComingPacket)eventArgs.Type;
                    if (incomingPacketType == InComingPacket.GameFlags)
                    {
                        InGame = true;
                    }
                    Log.Debug($"Received D2GS packet of type: {incomingPacketType} with data {eventArgs.Raw.ToPrintString()}");
                    PacketReceivedEventHandlers.GetValueOrDefault(incomingPacketType, p => Log.Debug($"Received unhandled D2GS packet of type: {incomingPacketType}"))?.Invoke(eventArgs);
                    SetPacketEventType(incomingPacketType);
                }
                else
                {
                    Log.Warning($"Received unknown D2GS packet of type: 0x{(byte)eventArgs.Type,2:X2} with data {eventArgs.Raw.ToPrintString()}");
                }
            };

            Connection.PacketSent += (obj, eventArgs) =>
            {
                if (Enum.IsDefined(typeof(OutGoingPacket), eventArgs.Type))
                {
                    var outgoingPacketType = (OutGoingPacket)eventArgs.Type;
                    Log.Debug($"Sent D2GS packet of type: {outgoingPacketType} with data {eventArgs.Raw.ToPrintString()}");
                    PacketSentEventHandlers.GetValueOrDefault(outgoingPacketType, null)?.Invoke(eventArgs);
                }
                else
                {
                    Log.Warning($"Send unknown D2GS packet of type: 0x{(byte)eventArgs.Type,2:X2} with data {eventArgs.Raw.ToPrintString()}");
                }
            };
        }
Ejemplo n.º 2
0
        public GameServer()
        {
            Connection.PacketReceived += (obj, eventArgs) => PacketReceivedEventHandlers.GetValueOrDefault(eventArgs.Type, null)?.Invoke(eventArgs);
            Connection.PacketSent     += (obj, eventArgs) => PacketSentEventHandlers.GetValueOrDefault(eventArgs.Type, null)?.Invoke(eventArgs);

            Connection.PacketReceived += (obj, packet) => Log.Verbose($"Received D2GS packet of type: 0x{(byte)packet.Type, 2:X2}");
            Connection.PacketSent     += (obj, packet) => Log.Verbose($"Sent D2GS packet of type: 0x{packet.Type,2:X2} {(D2gs)packet.Type}");

            OnReceivedPacketEvent(0x02, p => LoadSuccessEvent.Set());
        }
Ejemplo n.º 3
0
        internal RealmServer()
        {
            Connection.PacketReceived += (obj, eventArgs) => PacketReceivedEventHandlers.GetValueOrDefault((Mcp)eventArgs.Type, null)?.Invoke(eventArgs);
            Connection.PacketSent     += (obj, eventArgs) => PacketSentEventHandlers.GetValueOrDefault((Mcp)eventArgs.Type, null)?.Invoke(eventArgs);

            OnReceivedPacketEvent(Mcp.STARTUP, StartupEvent.Set);
            OnReceivedPacketEvent(Mcp.CHARLIST, ListCharactersEvent.Set);
            OnReceivedPacketEvent(Mcp.CHARLOGON, CharLogonEvent.Set);
            OnReceivedPacketEvent(Mcp.CREATEGAME, CreateGameEvent.Set);
            OnReceivedPacketEvent(Mcp.JOINGAME, JoinGameEvent.Set);
        }
Ejemplo n.º 4
0
        internal BattleNetChatServer()
        {
            _connectTrigger = _machine.SetTriggerParameters <string>(Trigger.Connect);

            _loginTrigger       = _machine.SetTriggerParameters <string, string>(Trigger.Login);
            _joinChannelTrigger = _machine.SetTriggerParameters <uint, string>(Trigger.JoinChannel);
            _chatCommandTrigger = _machine.SetTriggerParameters <string>(Trigger.ChatCommand);

            _machine.Configure(State.NotConnected)
            .Permit(Trigger.Connect, State.Connected);

            _machine.Configure(State.Connected)
            .OnEntryFrom <String>(_connectTrigger, OnConnect)
            .Permit(Trigger.VerifyClient, State.Verified)
            .Permit(Trigger.AuthorizeKeys, State.KeysAuthorized)
            .Permit(Trigger.Disconnect, State.NotConnected);

            _machine.Configure(State.KeysAuthorized)
            .SubstateOf(State.Connected)
            .OnEntryFrom(Trigger.AuthorizeKeys, OnAuthorizeKeys)
            .Permit(Trigger.Login, State.UserAuthenticated)
            .Permit(Trigger.Disconnect, State.NotConnected);

            _machine.Configure(State.UserAuthenticated)
            .SubstateOf(State.Connected)
            .SubstateOf(State.KeysAuthorized)
            .OnEntryFrom(_loginTrigger, (username, password) => OnLogin(username, password))
            .OnEntryFrom(Trigger.LeaveChat, OnLeaveChat)
            .Permit(Trigger.EnterChat, State.InChat)
            .Permit(Trigger.Disconnect, State.NotConnected);

            _machine.Configure(State.InChat)
            .SubstateOf(State.Connected)
            .SubstateOf(State.KeysAuthorized)
            .SubstateOf(State.UserAuthenticated)
            .OnEntryFrom(Trigger.EnterChat, OnEnterChat)
            .InternalTransition(_joinChannelTrigger, (flags, channel, t) => OnJoinChannel(flags, channel))
            .InternalTransition(_chatCommandTrigger, (message, t) => OnChatCommand(message))
            .Permit(Trigger.LeaveChat, State.UserAuthenticated)
            .Permit(Trigger.Disconnect, State.NotConnected);

            Connection.PacketReceived += (obj, packet) => PacketReceivedEventHandlers.GetValueOrDefault(packet.Type, null)?.Invoke(packet);
            Connection.PacketSent     += (obj, packet) => PacketSentEventHandlers.GetValueOrDefault(packet.Type, null)?.Invoke(packet);

            Connection.PacketReceived += (obj, packet) => Log.Verbose($"Received BNCS packet of type: {packet.Type}");

            OnReceivedPacketEvent(Sid.PING, packet => Connection.WritePacket(packet.Raw));
            OnReceivedPacketEvent(Sid.QUERYREALMS2, ListRealmsEvent.Set);
            OnReceivedPacketEvent(Sid.LOGONREALMEX, RealmLogonEvent.Set);
            OnReceivedPacketEvent(Sid.AUTH_CHECK, AuthCheckEvent.Set);
            OnReceivedPacketEvent(Sid.AUTH_INFO, AuthInfoEvent.Set);
            OnReceivedPacketEvent(Sid.ENTERCHAT, EnterChatEvent.Set);
            OnReceivedPacketEvent(Sid.LOGONRESPONSE2, LogonEvent.Set);
        }
Ejemplo n.º 5
0
        public GameServer()
        {
            Connection.PacketReceived += (obj, eventArgs)
                                         => PacketReceivedEventHandlers.GetValueOrDefault(eventArgs.Type, p => Log.Debug($"Received unhandled D2GS packet of type: 0x{(byte)p.Type,2:X2}"))?.Invoke(eventArgs);
            Connection.PacketSent += (obj, eventArgs) => PacketSentEventHandlers.GetValueOrDefault(eventArgs.Type, null)?.Invoke(eventArgs);

            Connection.PacketSent += (obj, packet) => Log.Verbose($"Sent D2GS packet of type: 0x{packet.Type,2:X2} {BitConverter.ToString(packet.Raw)}");

            OnReceivedPacketEvent(0x02, _ => LoadSuccessEvent.Set());
            OnReceivedPacketEvent(0x04, _ => LoadCompleteEvent.Set());
            OnReceivedPacketEvent(0xB0, _ => GameExitEvent.Set());
        }
Ejemplo n.º 6
0
 internal void OnReceivedPacketEvent(Mcp type, Action <McpPacket> handler)
 => PacketReceivedEventHandlers.AddOrUpdate(type, handler, (t, h) => h += handler);
Ejemplo n.º 7
0
 public void OnReceivedPacketEvent(Sid type, Action <BncsPacket> handler)
 => PacketReceivedEventHandlers.AddOrUpdate(type, handler, (t, h) => h += handler);
Ejemplo n.º 8
0
 internal void OnReceivedPacketEvent(InComingPacket type, Action <D2gsPacket> handler)
 => PacketReceivedEventHandlers.AddOrUpdate(type, handler, (t, h) => h += handler);