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()}"); } }; }
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); }
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); }