コード例 #1
0
ファイル: PacketResult.cs プロジェクト: Dentrax/EasySSA
 public PacketResult(PacketOperationType resultType)
 {
     ResultInfo = null;
     ResultType = resultType;
 }
コード例 #2
0
ファイル: PacketResult.cs プロジェクト: Dentrax/EasySSA
 public PacketResult(PacketOperationType resultType, PacketResultInfo resultInfo)
 {
     ResultInfo = resultInfo;
     ResultType = resultType;
 }
コード例 #3
0
ファイル: SROServiceContext.cs プロジェクト: Dentrax/EasySSA
        private void DOPacketTransfer(Packet packet, PacketSocketType direction, PacketResult result)
        {
            Security security = (direction == PacketSocketType.CLIENT) ? this.m_clientSecurity : this.m_serviceSecurity;

            PacketOperationType operation = result.ResultType;

            PacketResult.PacketResultInfo resultInfo = result.ResultInfo;

            switch (operation)
            {
            case PacketOperationType.DISCONNECT:
                if (resultInfo != null)
                {
                    if (resultInfo is PacketResult.PacketDisconnectResultInfo disconnect)
                    {
                        if (!string.IsNullOrEmpty(disconnect.Notice))
                        {
                            this.SendMessage(MessageType.NOTICE, disconnect.Notice.Trim());
                        }
                        if (disconnect.DisconnectReason != null)
                        {
                            int id = Convert.ToInt32(disconnect.DisconnectReason);
                            //TODO: Complete
                        }

                        if (ServiceComponent.IsDebugMode)
                        {
                            Logger.PACKET.Print(LogLevel.Warning, "Packet Operation (DISCONNECT) received : " + packet.HexOpcode);
                        }

                        this.Stop(ClientDisconnectType.PACKET_OPERATION_DISCONNECT);
                    }
                }
                break;

            case PacketOperationType.REPLACE:
                if (resultInfo != null)
                {
                    if (resultInfo is PacketResult.PacketReplaceResultInfo replace)
                    {
                        if (replace.Packet == packet)
                        {
                            if (ServiceComponent.IsDebugMode)
                            {
                                Logger.PACKET.Print(LogLevel.Warning, "Packet Operation (REPLACE) received : " + packet.HexOpcode);
                            }

                            replace.ReplaceWith.ForEach(packets => {
                                security.Send(packets);
                            });
                        }
                    }
                }
                break;

            case PacketOperationType.INJECT:
                if (resultInfo != null)
                {
                    if (resultInfo is PacketResult.PacketInjectResultInfo inject)
                    {
                        if (ServiceComponent.IsDebugMode)
                        {
                            Logger.PACKET.Print(LogLevel.Warning, "Packet Operation (INJECT) received : " + packet.HexOpcode);
                        }

                        if (!inject.AfterPacket)
                        {
                            security.Send(packet);
                        }

                        if (inject.Packet == packet)
                        {
                            inject.InjectWith.ForEach(packets => {
                                security.Send(packets);
                            });
                        }

                        if (inject.AfterPacket)
                        {
                            security.Send(packet);
                        }
                    }
                }
                break;

            case PacketOperationType.IGNORE:
                if (ServiceComponent.IsDebugMode)
                {
                    Logger.PACKET.Print(LogLevel.Warning, "Packet Operation (IGNORE) received : " + packet.HexOpcode);
                }
                break;

            case PacketOperationType.RESPONSE:
                if (resultInfo != null)
                {
                    if (resultInfo is PacketResult.PacketResponseResultInfo response)
                    {
                        if (ServiceComponent.IsDebugMode)
                        {
                            Logger.PACKET.Print(LogLevel.Warning, "Packet Operation (SEND) received : " + packet.HexOpcode);
                        }

                        response.Packets.ForEach(packets => {
                            security.Send(packets);
                        });
                    }
                }
                security.Send(packet);
                break;

            case PacketOperationType.NOTHING:
                security.Send(packet);
                break;

            default:
                security.Send(packet);
                break;
            }

            if (direction == PacketSocketType.CLIENT)
            {
                TransferToClient();
            }
            else if (direction == PacketSocketType.SERVER)
            {
                TransferToService();
            }
        }