예제 #1
0
    static void Main(string[] args)
    {
        Server server = new Server(7000);

        int i = 0;

        while (true)
        {
            string data = Console.ReadLine();

            PacketMessage message = new PacketMessage();
            message.data = data;

            if (i % 2 == 0)
            {
                server.SendBroad(message);
            }
            else
            {
                server.SendBroad(message);
                server.SendBroad(message);
            }
            ++i;
        }
    }
예제 #2
0
 public void BurnGaugeBroadcast()
 {
     using (BurnDataContext burnDataContext = new BurnDataContext())
     {
         try
         {
             int         num         = burnDataContext.AddAllUserEventCount(new int?(-99), new int?(0), new DateTime?(DateTime.MaxValue));
             BurnJackpot burnJackpot = MMOChannelContents.GetBurnJackpot();
             if (burnJackpot != null)
             {
                 if (this.LatestBurnGauge != num)
                 {
                     this.LatestBurnGauge = num;
                     foreach (KeyValuePair <long, Channel> keyValuePair in this.channels)
                     {
                         Channel       value   = keyValuePair.Value;
                         PacketMessage message = new PacketMessage
                         {
                             Data = SerializeWriter.ToBinary <ServiceCore.EndPointNetwork.BurnGauge>(new ServiceCore.EndPointNetwork.BurnGauge(num, burnJackpot.JackpotStart, burnJackpot.MaxReward))
                         };
                         value.BroadcastToColhenLobby(message);
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             Log <MMOChannelService> .Logger.Error("burn gauge broadcasting error", ex);
         }
     }
 }
예제 #3
0
        public void ConvertFromOutpost(ref PacketMessage packetMessage, ref FormControlBase formControl)
        {
            List <string> inlList = new List <string>();
            List <string> inrList = new List <string>();

            FormField[] formFields = packetMessage.FormFieldArray;
            if (packetMessage.MessageBody is null)
            {
                packetMessage.MessageBody = formControl.CreateOutpostData(ref packetMessage);
            }
            string[] msgLines = packetMessage.MessageBody.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);

            string value;

            foreach (FormField formField in formFields)
            {
                (string id, FrameworkElement control) = formControl.GetTagIndex(formField);
                value = FormControlBase.GetOutpostValue(id, ref msgLines);
                if (!string.IsNullOrEmpty(value))
                {
                    inrList.Add(value);
                    inlList.Add(id);
                }
            }
            ViewModel.InlList = inlList;
            ViewModel.InrList = inrList;
        }
예제 #4
0
        public override string CreateOutpostData(ref PacketMessage packetMessage)
        {
            switch (packetMessage.FormProvider)
            {
            case FormProviders.PacForm:
                outpostData = new List <string>()
                {
                    "!PACF! " + packetMessage.Subject,
                    "# JS:EOC MESSAGE FORM (which4) ",
                    "# JS-ver. PR-4.4-4.3, 05/02/18",
                    "# FORMFILENAME: XSC_ICS-213_Message_v070628.html"
                };
                break;

            case FormProviders.PacItForm:
                outpostData = new List <string>()
                {
                    "!SCCoPIFO!",
                    "#Subject: " + packetMessage.Subject,
                    "#T: form-ics213.html",
                    "#V: 1.1",
                };
                break;
            }
            CreateOutpostDataFromFormFields(ref packetMessage, ref outpostData);

            return(CreateOutpostMessageBody(outpostData));
        }
예제 #5
0
    // # CHAT
    void onReciveMessage(NetworkMessage msg)
    {
        PacketMessage message     = msg.ReadMessage <PacketMessage>();
        string        chatMessage = message.sender + ": " + message.message;

        this.player.getChat().addMessage(chatMessage);
    }
예제 #6
0
        protected PacketMessage ParsePacketMessage(string clientAddress, string paramString, ConnectType connectType)
        {
            ParamGeter paramGeter = new ParamGeter(paramString);
            PacketHead head       = new PacketHead(connectType, PacketMsgType.Request);

            head.Address  = clientAddress;
            head.MsgId    = paramGeter.GetInt("msgid");
            head.Uid      = paramGeter.GetInt("uid");
            head.ActionId = paramGeter.GetInt("actionId");
            string[] sidArray = paramGeter.GetString("sid").Split('|');
            if (sidArray.Length > 2)
            {
                head.GameId   = sidArray[1].ToInt();
                head.ServerId = sidArray[2].ToInt();
            }
            else
            {
                head.GameId   = paramGeter.GetInt("gametype");
                head.ServerId = paramGeter.GetInt("serverid");
            }
            head.EnableGzip = false;
            PacketMessage packet = new PacketMessage();

            packet.Head    = head;
            packet.Content = BufferUtils.GetBytes(paramString);
            return(packet);
        }
예제 #7
0
        /// <summary>
        /// Tcp客户端连接断开,通知业务层
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="clientPoint"></param>
        public void OnTcpClientClosed(object sender, EndPoint clientPoint)
        {
            var        token = ClientConnectManager.GetToken(clientPoint.ToString());
            PacketHead head  = new PacketHead(ConnectType.Tcp, PacketMsgType.Closed);

            head.GameId   = token.GameId;
            head.ServerId = token.ServerId;
            head.Uid      = token.Uid;
            var session = GameSessionManager.GetSession(head.GameId, head.ServerId);

            if (session == null)
            {
                return;
            }
            head.Address    = session.GameAddress;
            head.EnableGzip = false;
            PacketMessage packet = new PacketMessage();

            packet.Head    = head;
            packet.Content = new byte[0];
            if (CheckConnected(head.Address))
            {
                OnSendToGame(head.Address, packet.ToByte());
            }
        }
예제 #8
0
        public override void OnReceiveTimeout(string clientAddress, byte[] receiveData)
        {
            try
            {
                BufferReader reader      = new BufferReader(receiveData);
                string       paramString = reader.ReadPacketString();
                paramString = HttpUtility.UrlDecode(paramString, Encoding.UTF8);
                int index = paramString.IndexOf("?d=");
                if (index != -1)
                {
                    index      += 3;
                    paramString = paramString.Substring(index, paramString.Length - index);
                }
                PacketMessage receivePacket = ParsePacketMessage(clientAddress, paramString, ConnectType.Tcp);
                var           recHead       = receivePacket.Head;

                int         errorCode = LanguageHelper.GetLang().ErrorCode;
                string      errorMsg  = LanguageHelper.GetLang().RequestTimeout;
                MessageHead head      = new MessageHead(recHead.MsgId, recHead.ActionId, "st", errorCode, errorMsg);
                head.HasGzip = true;
                MessageStructure ds = new MessageStructure();
                ds.WriteBuffer(head);
                byte[] data = ds.ReadBuffer();
                OnSendCompleted(clientAddress, data);
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("Send to client {0} timeout error:{1}", clientAddress, ex);
            }
        }
예제 #9
0
        /// <summary>
        /// 从客户端接收数据
        /// </summary>
        /// <param name="clientAddress"></param>
        /// <param name="data"></param>
        public override void Receive(string clientAddress, byte[] data)
        {
            try
            {
                //解析头部信息,转换成统一的流格式:head[MsgType(1)+uid(4)+gameId(4)+serverId(4)+gzip(1)] + (len(4)+data)
                BufferReader reader      = new BufferReader(data);
                string       paramString = reader.ReadPacketString();
                paramString = HttpUtility.UrlDecode(paramString, Encoding.UTF8);
                int index = paramString.IndexOf("?d=");
                if (index != -1)
                {
                    index      += 3;
                    paramString = paramString.Substring(index, paramString.Length - index);
                }
                PacketMessage packet = ParsePacketMessage(clientAddress, paramString, ConnectType.Tcp);
                var           token  = new UserToken();
                token.GameId   = packet.Head.GameId;
                token.ServerId = packet.Head.ServerId;
                token.Uid      = packet.Head.Uid;
                ClientConnectManager.Push(clientAddress, token);

                if (ReceiveCompleted != null)
                {
                    //分发送到游戏服
                    byte[] packData   = packet.ToByte();
                    string successMsg = string.Format("{0}>>{1}接收到{2}字节!",
                                                      DateTime.Now.ToString("HH:mm:ss:ms"), clientAddress, data.Length);
                    ReceiveCompleted.BeginInvoke(clientAddress, packData, OnReceiveCompleted, successMsg);
                }
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("Receive form client {0} error:{1}", clientAddress, ex);
            }
        }
예제 #10
0
        public void Handle(IEntity entity, PacketMessage packet)
        {
            var id = packet.Data.ReadInt16() - 1;

            // find player
            var target = _players.Get(id);

            if (target == null)
            {
                return;
            }

            if (target.IsDead())
            {
                return;
            }

            if (target.Equals(entity.Handle))
            {
                return;
            }

            // target handle is good, make dir provider
            entity.SendMessage(EntityMessage.PlayerFollowTarget(target));
        }
예제 #11
0
        public void Handle(IEntity entity, PacketMessage packet)
        {
            var movement = entity.Components.Get <TileMovementComponent>();

            if (movement == null)
            {
                return;
            }

            var clientPos = entity.GetClientPosition();

            if (clientPos == null)
            {
                return;
            }

            // non-paired
            var rawWaypointNum = packet.Data.Buffer.Length - 1;

            // make sure it's an even number;
            if (rawWaypointNum % 2 != 0)
            {
                return;
            }

            var numWaypoints = rawWaypointNum / 2;

            // check if waypoint count is out of range
            if (0 >= numWaypoints || numWaypoints > MaxTiles)
            {
                return;
            }

            var deltaWaypoints = new(sbyte x, sbyte y)[numWaypoints];
예제 #12
0
        public void Request(HttpConnection connection, string clientAddress, byte[] data)
        {
            string paramString = string.Empty;

            try
            {
                paramString = Encoding.ASCII.GetString(data);
                PacketMessage packet = ParsePacketMessage(clientAddress, paramString, ConnectType.Http);
                packet.Head.SSID = connection.SSID.ToString("N");
                HttpConnectionManager.Push(connection);

                if (ReceiveCompleted != null)
                {
                    //分发送到游戏服
                    byte[] packData   = packet.ToByte();
                    string successMsg = string.Format("{0}>>{1}接收到{2}字节!",
                                                      DateTime.Now.ToString("HH:mm:ss:ms"), clientAddress, data.Length);
                    ReceiveCompleted.BeginInvoke(clientAddress, packData, OnReceiveCompleted, successMsg);
                }
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("Receive form http request:{0} error:{1}", paramString, ex);
            }
        }
예제 #13
0
        private void Exec(IEntity p, FollowPacketHandler h, short target)
        {
            var b = new Blob(16);

            b.Write16(target);
            h.HandleAll(p, o => PacketMessage.Success((byte)o, b));
        }
예제 #14
0
        public void GetPackageVersions(
            string repositoryName,
            string packageNames)
        {
            XmlMessageListPackages listPackagesMessage = XmlMessageCreator.CreateXmlMessageListPackages();

            List <string> packages = packageNames.Split(',').ToList <string>();

            listPackagesMessage.AddRepositoryPackages(repositoryName, packages);


            // create packet
            PacketMessage packetMessage =
                new PacketMessage(PacketMessageType.C_LIST_PACKAGE_VERSIONS, 0, listPackagesMessage.ToByteArray());

            byte[] packet = _packetManager.CreateMessage(packetMessage.GetMessageData());

            // send
            _clientSocket.Send(packet);

            // get response
            int rec = _clientSocket.Receive(_socketBuffer);

            byte[] data = new byte[rec];
            Array.Copy(_socketBuffer, data, rec);
            _packetManager.AddReceivedData(data);
        }
        public void Handle(IEntity entity, PacketMessage packet)
        {
            var buttonId    = packet.Data.ReadInt16();
            var interfaceId = packet.Data.ReadInt16();

            entity.SendMessage(new ButtonClickMessage(buttonId, interfaceId));
        }
예제 #16
0
 public void OnInvalidMessageReceive(object sender, PacketMessage message)
 {
     // stop reciving in case of error
     if (IsReceiving())
     {
         _state = PackageBuilderState.IDLE;
     }
 }
예제 #17
0
        public override string CreateOutpostData(ref PacketMessage packetMessage)
        {
            List <string> outpostData = new List <string>();

            CreateOutpostDataFromFormFields(ref packetMessage, ref outpostData);

            return(CreateOutpostMessageBody(outpostData));
        }
예제 #18
0
        /// <summary>
        /// 反序列化字节序为结构信息
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="error">错误信息</param>
        /// <returns></returns>
        public PacketMessage Decode(byte[] buffer, int offset, int count)
        {
            //建立数据包结构体对象并赋值
            PacketMessage packetInfo = new PacketMessage();

            if (count <= 14 || count >= 1040)
            {
                /*  throw new Exception(string.Format("数据包有效长度为>14 且 <=1040,当前字节长度...{0}", buffer.Length));*/
                packetInfo = null;
                return(packetInfo);
            }
            byte checknum = 0;

            //转义还原
            byte[] rawData = ReEscape(buffer, offset, count, ref checknum);

/*            //验证校验码
 *          if (checknum != rawData[rawData.Length - 1])
 *          {
 *              packetInfo = null;
 *              throw new Exception(string.Format("校验码不符合,值:dst[{0}]/src[{1}]", checknum, rawData[rawData.Length - 1]));
 *
 *          } */
            int pos = 0;

            //解析消息头
            packetInfo.pmPacketHead = DecodeRawHead(rawData, ref pos);
            if (packetInfo.pmPacketHead.phPacketHeadAttribute.paMessageBodyLength > 0)
            {
                int len = rawData.Length - pos - 1;

/*                //数据长度不符合
 *              if (packetInfo.pmPacketHead.phPacketHeadAttribute.paMessageBodyLength != len)
 *              {
 *//*throw new Exception(string.Format("原始数据体长度和目标长度不符:src[{0}]/dst[{1}]",
 *                      packetInfo.pmPacketHead.phPacketHeadAttribute.paMessageBodyLength, len));*//*
 *                  packetInfo = null;
 *                  return packetInfo;
 *              }*/
                if (len == -1)
                {
                    packetInfo = null;
                    return(packetInfo);
                }
                //消息体
                try
                {
                    packetInfo.pmMessageBody = new byte[len];
                    rawData.CopyTo(pos, packetInfo.pmMessageBody, 0, len);
                    //校验码
                    packetInfo.pmCheckcode = checknum;
                } catch {
                    packetInfo = null;
                    return(packetInfo);
                }
            }
            return(packetInfo);
        }
        private async void ConvertToForm_Click(object sender, RoutedEventArgs e)
        {
            //packetMsg.MessageBody = "
            //Message #1 \r\n
            //Date: Mon, 01 Feb 2016 12:29:03 PST\r\n
            //From: kz6dm @w3xsc.ampr.org\r\n
            //To: kz6dm\r\n
            //Subject: 6DM-907P_O/R_ICS213_Check-in\r\n
            //!PACF!6DM-907P_O/R_ICS213_Check-in\r\n
            //# EOC MESSAGE FORM \r\n
            //# JS-ver. PR-4.1-3.1, 01/19/17,\r\n
            //# FORMFILENAME: Message.html\r\n
            //MsgNo: [6DM - 907P]\r\n
            //1a.: [02/01/2016]\r\n
            //1b.: [1219]\r\n4.: [OTHER]\r\n5.: [ROUTINE]\r\n7.: [Operations]\r\n9a.: [MTVEOC]\r\n8.: [Operations]\r\n9b.: [HOSECM]\r\n10.: [Check-in]\r\n12.: [\\nMonday Check-in]\r\nRec-Sent: [sent]\r\nMethod: [Other]\r\nOther: [Packet]\r\nOpCall: [KZ6DM]\r\nOpName: [Poul Hansen]\r\nOpDate: []\r\nOpTime: []\r\n# EOF\r\n";

            // read data
            //!PACF!6DM - 681P_O / R_ICS213_ghjhgj
            //# EOC MESSAGE FORM
            //# JS-ver. PR-4.1-3.1, 01/19/17
            //# FORMFILENAME: Message.html
            //MsgNo: [6DM - 681P]
            //1a.: [03/01/18]
            //1b.: [1650]
            //4.: [OTHER]
            //5.: [ROUTINE]
            //9a.: [gfhjgfj]
            //9b.: [gfhjgfhj]
            //10.: [ghjhgj]
            //12.: [\nghjghj]
            //Rec-Sent: [sent]
            //Method: [Other]
            //Other: [Packet]
            //OpCall: [KZ6DM]
            //OpName: [Poul Hansen]
            //OpDate: [03/01/2018]
            //OpTime: [1652]
            //#EOF

            // Find type
            // do a navigate to forms with index and form id (maybe file name}
            PacketMessage message = new PacketMessage()
            {
                ReceivedTime  = DateTime.Parse(messageReceivedTime.Text),
                MessageNumber = SettingsPageViewModel.GetMessageNumberPacket(),
                TNCName       = "E-Mail",
            };

            message.MessageBody  = $"Date: {message.ReceivedTime}\r\n";
            message.MessageBody += $"From: {messageTo.Text}\r\n";
            message.MessageBody += $"To: {messageFrom.Text}\r\n";
            message.MessageBody += $"Subject: {messageSubject.Text}\r\n";
            message.MessageBody += PacFormText.Text;
            CommunicationsService communicationsService = CommunicationsService.CreateInstance();

            communicationsService.CreatePacketMessageFromMessageAsync(ref message);
        }
        private void OnPackageFileDataEndReceived(PacketMessage packetMessage)
        {
            //Console.WriteLine("DEBUG: Received S_PACKAGE_FILE_END");

            if (PackageFileDataEndReceived != null)
            {
                PackageFileDataEndReceived(this, null);
            }
        }
        private void OnPackageFileDataReceived(PacketMessage packetMessage)
        {
            //Console.WriteLine("DEBUG: Received S_PACKAGE_FILE_DATA part " + packetMessage.Part);

            if (PackageFileDataReceived != null)
            {
                PackageFileDataReceived(this, packetMessage);
            }
        }
예제 #22
0
 private void OnSocketClosing(object sender, EndPoint gamePoint)
 {
     if (sender is byte[])
     {
         PacketMessage packet = PacketMessage.Parse(sender as byte[]);
         PacketMessage error  = PacketMessage.CreateError(packet.Head, MessageError.SystemError, LanguageHelper.GetLang().ServerBusy);
         OnSendToClient(packet.Head.Address, error.ToByte());
     }
 }
예제 #23
0
    public void sendMessage(string message, MessageTypes type, string reciver = "")
    {
        PacketMessage msg = new PacketMessage();

        msg.sender  = this.player.playerName;
        msg.reciver = reciver;
        msg.message = message;
        msg.type    = type;
        con.Send(PacketTypes.SEND_MESSAGE, msg);
    }
        private void Exec(ChatPacketHandler h, IEntity p, ChatMessage.TextEffect e, ChatMessage.TextColor c, string m)
        {
            var b = new Blob(512);

            b.Write((byte)e);
            b.Write((byte)c);
            b.WriteString(m);

            h.HandleAll(p, o => PacketMessage.Success((byte)o, b));
        }
        private void OnInvalidMessageReceived(PacketMessage packetMessage)
        {
            Console.WriteLine("ERROR: Invalid message type received - " + packetMessage.Type.ToString());
            //Console.WriteLine("DEBUG: Received invalid message");

            if (InvalidMessageReceived != null)
            {
                InvalidMessageReceived(this, packetMessage);
            }
        }
예제 #26
0
        /// <summary>
        /// 从游戏服接收数据
        /// </summary>
        /// <param name="gameAddress">游戏服的地址</param>
        /// <param name="data"></param>
        public override void Receive(string gameAddress, byte[] data)
        {
            try
            {
                PacketMessage packet  = PacketMessage.Parse(data);
                var           head    = packet.Head;
                GameSession   session = null;
                switch (head.MsgType)
                {
                case PacketMsgType.None:
                    //心跳包
                    session = GameSessionManager.GetSession(head.GameId, head.ServerId);
                    if (session != null)
                    {
                        session.GameAddress = gameAddress;
                        session.AccessTime  = DateTime.Now;
                        Console.WriteLine("{0}>>Connect to host of game server {1}-{2} from {3}", DateTime.Now.ToLongTimeString(), head.GameId, head.ServerId, gameAddress);
                    }
                    break;

                case PacketMsgType.Register:
                    session             = new GameSession(head.GameId, head.ServerId);
                    session.GameAddress = gameAddress;
                    session.AccessTime  = DateTime.Now;
                    GameSessionManager.Register(session);
                    break;

                case PacketMsgType.Push:
                    OnSendToClient(head.Address, data);
                    break;

                case PacketMsgType.SendTo:
                case PacketMsgType.Request:
                    //发送到其它通道
                    Send(head.Address, packet.ToByte());
                    break;

                case PacketMsgType.Broadcast:
                    //广播到客户端
                    var clientPointList = ClientConnectManager.FindAll(head.GameId, head.ServerId);
                    foreach (var endPoint in clientPointList)
                    {
                        OnSendToClient(endPoint.ToString(), data);
                    }
                    break;

                default:
                    throw new Exception(string.Format("The message type:{0} is not supported.", head.MsgType));
                }
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("Receive game {0} error:{1}", gameAddress, ex);
            }
        }
        private void OnPackageDataHeaderReceived(PacketMessage packetMessage)
        {
            XmlDocument xmlDocument = CreateXmlDocumentFromMessage(packetMessage);
            //Console.WriteLine("DEBUG: Received S_PACKAGE_DATA_HEADER: " + xmlDocument.OuterXml);
            XmlMessagePackageDataHeader message = XmlMessageCreator.CreateXmlMessagePackageDataHeader(xmlDocument);

            if (PackageDataHeaderReceived != null)
            {
                PackageDataHeaderReceived(this, message);
            }
        }
        private void OnListPackageVersionsReceived(PacketMessage packetMessage)
        {
            XmlDocument xmlDocument = CreateXmlDocumentFromMessage(packetMessage);
            //Console.WriteLine("DEBUG: Received S_PACKAGE_VERSIONS: " + xmlDocument.OuterXml);
            XmlMessageListPackageVersions message = XmlMessageCreator.CreateXmlMessageListPackageVersions(xmlDocument);

            if (ListPackageVersionsReceived != null)
            {
                ListPackageVersionsReceived(this, message);
            }
        }
        private XmlDocument CreateXmlDocumentFromMessage(PacketMessage packetMessage)
        {
            XmlDocument xmlDocument = new XmlDocument();

            using (MemoryStream memoryStream = new MemoryStream(packetMessage.Data))
            {
                xmlDocument.Load(memoryStream);
            }

            return(xmlDocument);
        }
        private void OnPackageFileDataBeginReceived(PacketMessage packetMessage)
        {
            XmlDocument xmlDocument = CreateXmlDocumentFromMessage(packetMessage);
            //Console.WriteLine("DEBUG: Received S_PACKAGE_FILE_BEGIN: " + xmlDocument.OuterXml);
            XmlMessagePackageFileBegin message = XmlMessageCreator.CreateXmlMessagePackageFileBegin(xmlDocument);

            if (PackageFileDataBeginReceived != null)
            {
                PackageFileDataBeginReceived(this, message);
            }
        }
예제 #31
0
 protected override void OnSendToClient(PacketMessage packet)
 {
     if (packet.Head.ConnectType == ConnectType.Http)
     {
         string ssid = packet.Head.SSID;
         var connection = HttpConnectionManager.Get(ssid);
         if (connection != null)
         {
             connection.TimeoutTimer.Dispose();
             OnResponseCompleted(connection, packet.Content);
         }
         else
         {
             Console.WriteLine("Error of http connection is empty.");
         }
         return;
     }
     base.OnSendToClient(packet);
 }
예제 #32
0
 /// <summary>
 /// Tcp客户端连接断开,通知业务层
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="clientPoint"></param>
 public void OnTcpClientClosed(object sender, EndPoint clientPoint)
 {
     var token = ClientConnectManager.GetToken(clientPoint.ToString());
     PacketHead head = new PacketHead(ConnectType.Tcp, PacketMsgType.Closed);
     head.GameId = token.GameId;
     head.ServerId = token.ServerId;
     head.Uid = token.Uid;
     var session = GameSessionManager.GetSession(head.GameId, head.ServerId);
     if (session == null)
     {
         return;
     }
     head.Address = session.GameAddress;
     head.EnableGzip = false;
     PacketMessage packet = new PacketMessage();
     packet.Head = head;
     packet.Content = new byte[0];
     if (CheckConnected(head.Address))
     {
         OnSendToGame(head.Address, packet.ToByte());
     }
 }
예제 #33
0
 protected virtual void OnSendToClient(PacketMessage packet)
 {
     var clientAddress = packet.Head.Address;
     byte[] content = packet.Content;
     if (!packet.Head.EnableGzip)
     {
         //gzip压缩包
         MessageStructure ds = new MessageStructure();
         ds.WriteGzipBuffer(content);
         packet.Content = ds.ReadBuffer();
     }
     byte[] data = packet.Content;
     OnSendCompleted(clientAddress, data);
 }
예제 #34
0
 protected PacketMessage ParsePacketMessage(string clientAddress, string paramString, ConnectType connectType)
 {
     ParamGeter paramGeter = new ParamGeter(paramString);
     PacketHead head = new PacketHead(connectType, PacketMsgType.Request);
     head.Address = clientAddress;
     head.MsgId = paramGeter.GetInt("msgid");
     head.Uid = paramGeter.GetInt("uid");
     head.ActionId = paramGeter.GetInt("actionId");
     string[] sidArray = paramGeter.GetString("sid").Split('|');
     if (sidArray.Length > 2)
     {
         head.GameId = sidArray[1].ToInt();
         head.ServerId = sidArray[2].ToInt();
     }
     else
     {
         head.GameId = paramGeter.GetInt("gametype");
         head.ServerId = paramGeter.GetInt("serverid");
     }
     head.EnableGzip = false;
     PacketMessage packet = new PacketMessage();
     packet.Head = head;
     packet.Content = BufferUtils.GetBytes(paramString);
     return packet;
 }