示例#1
0
        public static void Process(JsonPacketData packet)
        {
            var packetType = (PACKET_ID)packet.PacketID;

            switch (packetType)
            {
                case PACKET_ID.SYSTEM_DISCONNECTD:
                    MainFormRef.SetDisconnectd();
                    break;

                case PACKET_ID.RESPONSE_LOGIN:
                    {
                        var resData = JsonEnDecode.Decode<JsonPacketResponseLogin>(packet.JsonFormatData);
                        var errorCode = (ERROR_CODE)resData.Result;

                        if (errorCode == ERROR_CODE.NONE)
                        {
                            MainFormRef.SetClientStatus(CLIENT_STATUS.LOGIN);
                            DevLog.Write(string.Format("로그인 성공"), LOG_LEVEL.INFO);
                        }
                        else
                        {
                            DevLog.Write(string.Format("로그인 실패:{0}", errorCode.ToString()), LOG_LEVEL.ERROR);
                        }
                    }
                    break;

                default:
                    break;
            }
        }
        void ReadPacketQueueProcess(object sender, EventArgs e)
        {
            ProcessLog();

            try
            {
                JsonPacketData packet = null;
                lock (((System.Collections.ICollection)RecvPacketQueue).SyncRoot)
                {
                    if (RecvPacketQueue.Count() > 0)
                    {
                        packet = RecvPacketQueue.Dequeue();
                    }
                }

                if (packet != null)
                {
                    PacketHandler.Process(packet);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("ReadPacketQueueProcess. error:{0}", ex.Message));
            }
        }
        public static void Process(JsonPacketData packet)
        {
            var packetType = (PACKET_ID)packet.PacketID;

            switch (packetType)
            {
            case PACKET_ID.SYSTEM_DISCONNECTD:
                MainFormRef.SetDisconnectd();
                break;

            case PACKET_ID.RESPONSE_LOGIN:
            {
                var resData   = JsonEnDecode.Decode <JsonPacketResponseLogin>(packet.JsonFormatData);
                var errorCode = (ERROR_CODE)resData.Result;

                if (errorCode == ERROR_CODE.NONE)
                {
                    MainFormRef.SetClientStatus(CLIENT_STATUS.LOGIN);
                    DevLog.Write(string.Format("로그인 성공"), LOG_LEVEL.INFO);
                }
                else
                {
                    DevLog.Write(string.Format("로그인 실패:{0}", errorCode.ToString()), LOG_LEVEL.ERROR);
                }
            }
            break;

            default:
                break;
            }
        }
示例#4
0
        void NetworkReadProcess()
        {
            while (IsNetworkThreadRunning)
            {
                if (Network.IsConnected() == false)
                {
                    continue;
                }

                var recvData = Network.Receive();

                if (recvData.Count > 0)
                {
                    PacketBuffer.Write(recvData.Array, recvData.Offset, recvData.Count);

                    while (true)
                    {
                        var data = PacketBuffer.Read();
                        if (data.Count < 1)
                        {
                            break;
                        }

                        var packet = new JsonPacketData();
                        packet.PacketID       = BitConverter.ToUInt16(data.Array, data.Offset);
                        packet.PacketOption   = BitConverter.ToUInt32(data.Array, data.Offset + 2);
                        packet.DataCRC        = BitConverter.ToUInt32(data.Array, data.Offset + 6);
                        packet.DataSize       = BitConverter.ToUInt16(data.Array, data.Offset + 10);
                        packet.JsonFormatData = new byte[packet.DataSize];
                        Buffer.BlockCopy(recvData.Array, (recvData.Offset + 12), packet.JsonFormatData, 0, (data.Count - 12));

                        lock (((System.Collections.ICollection)RecvPacketQueue).SyncRoot)
                        {
                            RecvPacketQueue.Enqueue(packet);
                        }
                    }
                }
                else
                {
                    var packet = new JsonPacketData();
                    packet.PacketID = PACKET_ID_DISCONNECTED;
                    packet.DataSize = 0;

                    lock (((System.Collections.ICollection)RecvPacketQueue).SyncRoot)
                    {
                        RecvPacketQueue.Enqueue(packet);
                    }
                }
            }
        }
示例#5
0
        void ReadPacketQueueProcess(object sender, EventArgs e)
        {
            ProcessLog();

            try
            {
                JsonPacketData packet = null;
                lock (((System.Collections.ICollection)RecvPacketQueue).SyncRoot)
                {
                    if (RecvPacketQueue.Count() > 0)
                    {
                        packet = RecvPacketQueue.Dequeue();
                    }
                }

                if (packet != null)
                {
                    switch (packet.PacketID)
                    {
                    case PACKET_ID_DISCONNECTED:
                        SetDisconnectd();
                        break;

                    case PACKET_ID_ECHO:
                    {
                        var resData = JsonEnDecode.Decode <JsonPacketNoticeEcho>(packet.JsonFormatData);

                        textBoxSendChat.Text = "";
                        var msg = string.Format("[ECHO]: {0}", resData.Msg);
                        listBoxLog.Items.Add(msg);
                    }
                    break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("ReadPacketQueueProcess. error:{0}", ex.Message));
            }
        }
示例#6
0
        void NetworkReadProcess()
        {
            while (IsNetworkThreadRunning)
            {
                if (Network.IsConnected() == false)
                {
                    continue;
                }

                var recvData = Network.Receive();

                if (recvData.Count > 0)
                {
                    PacketBuffer.Write(recvData.Array, recvData.Offset, recvData.Count);

                    while (true)
                    {
                        var data = PacketBuffer.Read();
                        if (data.Count < 1)
                        {
                            break;
                        }

                        var packet = new JsonPacketData();
                        packet.PacketID = BitConverter.ToUInt16(data.Array, data.Offset);
                        packet.PacketOption = BitConverter.ToUInt32(data.Array, data.Offset+2);
                        packet.DataCRC = BitConverter.ToUInt32(data.Array, data.Offset+6);
                        packet.DataSize = BitConverter.ToUInt16(data.Array, data.Offset+10);
                        packet.JsonFormatData = new byte[packet.DataSize];
                        Buffer.BlockCopy(recvData.Array, (recvData.Offset + 12), packet.JsonFormatData, 0, (data.Count - 12));

                        lock (((System.Collections.ICollection)RecvPacketQueue).SyncRoot)
                        {
                            RecvPacketQueue.Enqueue(packet);
                        }
                    }
                }
                else
                {
                    var packet = new JsonPacketData();
                    packet.PacketID = (ushort)PACKET_ID.SYSTEM_DISCONNECTD;
                    packet.DataSize = 0;

                    lock (((System.Collections.ICollection)RecvPacketQueue).SyncRoot)
                    {
                        RecvPacketQueue.Enqueue(packet);
                    }
                }
            }
        }
        public static void Process(JsonPacketData packet)
        {
            var packetType = (PACKET_ID)packet.PacketID;

            switch (packetType)
            {
                case PACKET_ID.SYSTEM_DISCONNECTD:
                    MainFormRef.SetDisconnectd();
                    break;

                case PACKET_ID.RESPONSE_LOGIN:
                    {
                        //var resData = JsonEnDecode.Decode<JsonPacketResponseLogin>(packet.JsonFormatData);
                        //var errorCode = (ERROR_CODE)resData.Result;

                        //if (errorCode == ERROR_CODE.NONE)
                        //{
                        //    MainFormRef.SetClientStatus(CLIENT_STATUS.LOGIN);
                        //    DevLog.Write(string.Format("로그인 성공"), LOG_LEVEL.INFO);
                        //}
                        //else
                        //{
                        //    DevLog.Write(string.Format("로그인 실패:{0}", errorCode.ToString()), LOG_LEVEL.ERROR);
                        //}
                    }
                    break;

                case PACKET_ID.RESPONSE_ENTER_LOBBY:
                    {
                        //var resData = JsonEnDecode.Decode<JsonPacketResponseEnterLobby>(packet.JsonFormatData);

                        //var errorCode = (ERROR_CODE)resData.Result;

                        //if (errorCode == ERROR_CODE.NONE)
                        //{
                        //    MainFormRef.SetClientStatus(CLIENT_STATUS.LOBBY);
                        //    DevLog.Write(string.Format("로비 입장 성공"), LOG_LEVEL.INFO);
                        //}
                        //else
                        //{
                        //    DevLog.Write(string.Format("로비 입장 실패:{0}", errorCode.ToString()), LOG_LEVEL.ERROR);
                        //}
                    }
                    break;

                case PACKET_ID.RESPONSE_LEAVE_LOBBY:
                    {
                        //var resData = JsonEnDecode.Decode<JsonPacketResponseLeaveLobby>(packet.JsonFormatData);

                        //var errorCode = (ERROR_CODE)resData.Result;

                        //if (errorCode == ERROR_CODE.NONE)
                        //{
                        //    MainFormRef.SetClientStatus(CLIENT_STATUS.LOGIN);
                        //    DevLog.Write(string.Format("로비 나가기 성공"), LOG_LEVEL.INFO);
                        //}
                        //else
                        //{
                        //    DevLog.Write(string.Format("로비 나가기 실패:{0}", errorCode.ToString()), LOG_LEVEL.ERROR);
                        //}
                    }
                    break;

                case PACKET_ID.NOTICE_CHAT:
                    {
                        //var resData = JsonEnDecode.Decode<JsonPacketNoticeChat>(packet.JsonFormatData);

                        //var errorCode = (ERROR_CODE)resData.Result;

                        //if (errorCode == ERROR_CODE.NONE)
                        //{
                        //    MainFormRef.ChatToUI(resData.UserID, resData.Chat);
                        //}
                        //else
                        //{
                        //    DevLog.Write(string.Format("로비 채팅 실패:{0}", errorCode.ToString()), LOG_LEVEL.ERROR);
                        //}
                    }
                    break;
                default:
                    break;
            }
        }
示例#8
0
        public static void Process(JsonPacketData packet)
        {
            var packetType = (PACKET_ID)packet.PacketID;

            switch (packetType)
            {
            case PACKET_ID.SYSTEM_DISCONNECTD:
                MainFormRef.SetDisconnectd();
                break;

            case PACKET_ID.RESPONSE_LOGIN:
            {
                var resData   = JsonEnDecode.Decode <JsonPacketResponseLogin>(packet.JsonFormatData);
                var errorCode = (ERROR_CODE)resData.Result;

                if (errorCode == ERROR_CODE.NONE)
                {
                    MainFormRef.SetClientStatus(CLIENT_STATUS.LOGIN);
                    DevLog.Write(string.Format("로그인 성공"), LOG_LEVEL.INFO);
                }
                else
                {
                    DevLog.Write(string.Format("로그인 실패:{0}", errorCode.ToString()), LOG_LEVEL.ERROR);
                }
            }
            break;

            case PACKET_ID.RESPONSE_ENTER_LOBBY:
            {
                var resData = JsonEnDecode.Decode <JsonPacketResponseEnterLobby>(packet.JsonFormatData);

                var errorCode = (ERROR_CODE)resData.Result;

                if (errorCode == ERROR_CODE.NONE)
                {
                    MainFormRef.SetClientStatus(CLIENT_STATUS.LOBBY);
                    DevLog.Write(string.Format("로비 입장 성공"), LOG_LEVEL.INFO);
                }
                else
                {
                    DevLog.Write(string.Format("로비 입장 실패:{0}", errorCode.ToString()), LOG_LEVEL.ERROR);
                }
            }
            break;

            case PACKET_ID.RESPONSE_LEAVE_LOBBY:
            {
                var resData = JsonEnDecode.Decode <JsonPacketResponseLeaveLobby>(packet.JsonFormatData);

                var errorCode = (ERROR_CODE)resData.Result;

                if (errorCode == ERROR_CODE.NONE)
                {
                    MainFormRef.SetClientStatus(CLIENT_STATUS.LOGIN);
                    DevLog.Write(string.Format("로비 나가기 성공"), LOG_LEVEL.INFO);
                }
                else
                {
                    DevLog.Write(string.Format("로비 나가기 실패:{0}", errorCode.ToString()), LOG_LEVEL.ERROR);
                }
            }
            break;

            case PACKET_ID.NOTICE_CHAT:
            {
                var resData = JsonEnDecode.Decode <JsonPacketNoticeChat>(packet.JsonFormatData);

                var errorCode = (ERROR_CODE)resData.Result;

                if (errorCode == ERROR_CODE.NONE)
                {
                    MainFormRef.ChatToUI(resData.UserID, resData.Chat);
                }
                else
                {
                    DevLog.Write(string.Format("로비 채팅 실패:{0}", errorCode.ToString()), LOG_LEVEL.ERROR);
                }
            }
            break;

            default:
                break;
            }
        }