Beispiel #1
0
        public void SystemClientDisConnected(SFNETPacket packet)
        {
            var user = UserManagerRef.GetUser(packet.SessionID());

            if (user == null)
            {
                return;
            }

            if (user.LobbyID > 0)
            {
                var jsonData = new JsonPacketRequestLeaveLobby()
                {
                    LobbyID = user.LobbyID, UserID = user.UserID
                };
                var bodyData = JsonEnDecode.Encode <JsonPacketRequestLeaveLobby>(jsonData);

                var InnerPacket = new CgsfNET64Lib.SFNETPacket();
                InnerPacket.SetData(-1, (ushort)PACKET_ID.REQUEST_LEAVE_LOBBY, bodyData);
                RelayPacketPacketProcess.RelayPacket(user.LobbyID, InnerPacket);
            }


            var result = UserManagerRef.RemoveUser(packet.SessionID());

            InnerMessageQueue.CurrentUserCount(UserManagerRef.GetConnectCount());

            DevLog.Write(string.Format("Client DisConnected. SessionID: {0}", packet.SessionID()), LOG_LEVEL.INFO);
        }
Beispiel #2
0
        public void RequestLogin(SFNETPacket packet)
        {
            var user = UserManagerRef.GetUser(packet.SessionID());

            if (user == null)
            {
                return;
            }

            try
            {
                if (user.CurrentState != CONNECT_USER_STATE.NONE)
                {
                    return;
                }

                var request = JsonEnDecode.Decode <CSCommonLib.JsonPacketRequestLogin>(packet.GetData());

                // DB 작업 의뢰한다.
                var dbReqLogin = new DB.RequestLogin()
                {
                    PW = request.PW
                };
                var serializer = MessagePackSerializer.Get <DB.RequestLogin>();
                var jobDatas   = serializer.PackSingleObject(dbReqLogin);

                InsertDBRequest(PACKET_ID.DB_REQUEST_LOGIN, packet.SessionID(), request.ID, jobDatas);

                DevLog.Write("DB에 로그인 요청 보냄", LOG_LEVEL.DEBUG);
            }
            catch (Exception ex)
            {
                DevLog.Write(ex.ToString(), LOG_LEVEL.DEBUG);
            }
        }
        // 로비 입장/나가기
        private void btnLobbyEnterLeave_Click(object sender, EventArgs e)
        {
            if (ClientStatus == CLIENT_STATUS.LOBBY)
            {
                var request = new JsonPacketRequestLeaveLobby()
                {
                    LobbyID = textBoxLobbyID.Text.ToInt16(),
                    UserID  = textBoxUserID.Text
                };

                var bodyData = JsonEnDecode.Encode <JsonPacketRequestLeaveLobby>(request);
                PostSendPacket((UInt16)PACKET_ID.REQUEST_LEAVE_LOBBY, bodyData);
                return;
            }


            if (ClientStatus == CLIENT_STATUS.LOGIN)
            {
                var request = new JsonPacketRequestEnterLobby()
                {
                    LobbyID = textBoxLobbyID.Text.ToInt16(),
                    UserID  = textBoxUserID.Text
                };

                var bodyData = JsonEnDecode.Encode <JsonPacketRequestEnterLobby>(request);
                PostSendPacket((UInt16)PACKET_ID.REQUEST_ENTER_LOBBY, bodyData);
            }
            else
            {
                MessageBox.Show("로그인 상태가 아니거나 이미 로비에 입장한 상태입니다");
            }
        }
Beispiel #4
0
        public void RequestEnterLobby(SFNETPacket packet)
        {
            var user = UserManagerRef.GetUser(packet.SessionID());

            if (user == null)
            {
                return;
            }

            try
            {
                var request = JsonEnDecode.Decode <CSCommonLib.JsonPacketRequestEnterLobby>(packet.GetData());

                if (user.CurrentState != CONNECT_USER_STATE.ATUH_COMPLETE || user.UserID != request.UserID)
                {
                    return;
                }

                user.TryEnterLobby();

                RelayPacketPacketProcess.RelayPacket(request.LobbyID, packet);
            }
            catch (Exception ex)
            {
                DevLog.Write(ex.ToString(), LOG_LEVEL.DEBUG);
            }
        }
        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;
            }
        }
Beispiel #6
0
        public void RequestLogin(SFNETPacket packetData, ConnectUser user)
        {
            try
            {
                var request = JsonEnDecode.Decode <JsonPacketRequestLogin>(packetData.GetData());

                // 이미 등록된 유저인가? serial, ID
                var result = UserManagerRef.AddUser(packetData.SessionID(), request.ID);

                var response = new JsonPacketResponseLogin()
                {
                    Result = result
                };
                ServerNetworkRef.Send <JsonPacketResponseLogin>(packetData.SessionID(), PACKET_ID.RESPONSE_LOGIN, response);

                DevLog.Write(string.Format("[Login] result:{0}, UserID:{1}, SessionID{2}", result.ToString(), request.ID, packetData.SessionID()), LOG_LEVEL.INFO);
            }
            catch (Exception)
            {
                var response = new JsonPacketResponseLogin()
                {
                    Result = ERROR_CODE.ERROR
                };
                ServerNetworkRef.Send <JsonPacketResponseLogin>(packetData.SessionID(), PACKET_ID.RESPONSE_LOGIN, response);
            }
        }
Beispiel #7
0
        // 에코
        private void button1_Click(object sender, EventArgs e)
        {
            var request = new JsonPacketNoticeEcho()
            {
                Msg = textBoxSendChat.Text
            };
            var bodyData = JsonEnDecode.Encode <JsonPacketNoticeEcho>(request);

            PostSendPacket((UInt16)PACKET_ID_ECHO, bodyData);
        }
Beispiel #8
0
 public void RequestChat(SFNETPacket packetData)
 {
     try
     {
         var request = JsonEnDecode.Decode <JsonPacketRequestChat>(packetData.GetData());
         LobbyManagerRef.LobbyChat(request.LobbyID, request.UserID, request.Chat);
     }
     catch
     {
     }
 }
Beispiel #9
0
        public void ResponseRegistServer(SFNETPacket packetData)
        {
            try
            {
                var request = JsonEnDecode.Decode <JsonPacketResponseReqistServer>(packetData.GetData());


                DevLog.Write(string.Format("result:{0}, ServerName:{1}, SessionID: {2}", request.Result.ToString(), request.ServerName, packetData.SessionID()), LOG_LEVEL.INFO);
            }
            catch
            {
            }
        }
        // 채팅 보내기
        private void button5_Click(object sender, EventArgs e)
        {
            if (ClientStatus != CLIENT_STATUS.LOBBY)
            {
                MessageBox.Show("채팅은 로비에 입장해야만 가능합니다");
                return;
            }

            var request = new JsonPacketRequestChat()
            {
                Chat = textBoxSendChat.Text
            };
            var bodyData = JsonEnDecode.Encode <JsonPacketRequestChat>(request);

            PostSendPacket((UInt16)PACKET_ID.REQUEST_CHAT, bodyData);
        }
        // 로그인 하기
        private void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBoxUserID.Text))
            {
                MessageBox.Show("사용할 ID를 입력해 주세요");
                return;
            }

            var request = new JsonPacketRequestLogin()
            {
                ID = textBoxUserID.Text
            };
            var bodyData = JsonEnDecode.Encode <JsonPacketRequestLogin>(request);

            PostSendPacket((UInt16)PACKET_ID.REQUEST_LOGIN, bodyData);
        }
Beispiel #12
0
        public void InnerRoolBackEnterLobby(SFNETPacket packet)
        {
            try
            {
                var request = JsonEnDecode.Decode <JsonPacketInnerRollBackEnterLobby>(packet.GetData());

                // 로비에 추가
                var error = LobbyManagerRef.LeaveLobby(request.LobbyID, request.UserID);

                if (error == ERROR_CODE.NONE)
                {
                    InnerMessageQueue.CurrentLobbyUserCount(request.LobbyID, LobbyManagerRef.LobbyCurrentUserCount(request.LobbyID));
                }
            }
            catch
            {
            }
        }
Beispiel #13
0
        /// <summary>
        /// 패킷 처리
        /// </summary>
        private void ProcessProcket()
        {
            var packet = ServerNet.GetPacket();

            if (packet == null)
            {
                return;
            }

            switch (packet.GetPacketType())
            {
            case CgsfNET64Lib.SFPACKET_TYPE.CONNECT:
                SessionList.Add(packet.SessionID());
                DevLog.Write(string.Format("[OnConnect] Serial:{0}", packet.SessionID()), LOG_LEVEL.INFO);
                break;

            case CgsfNET64Lib.SFPACKET_TYPE.DISCONNECT:
                SessionList.Remove(packet.SessionID());
                DevLog.Write(string.Format("[OnDisConnect] Serial:{0}", packet.SessionID()), LOG_LEVEL.INFO);
                break;

            case CgsfNET64Lib.SFPACKET_TYPE.DATA:
                switch (packet.PacketID())
                {
                case PACKET_ID_ECHO:
                    var resData = JsonEnDecode.Decode <JsonPacketNoticeEcho>(packet.GetData());
                    DevLog.Write(string.Format("[Chat] Serial:{0}, Msg:{1}", packet.SessionID(), resData.Msg), LOG_LEVEL.INFO);

                    var request = new JsonPacketNoticeEcho()
                    {
                        Msg = resData.Msg
                    };
                    var bodyData = JsonEnDecode.Encode <JsonPacketNoticeEcho>(request);
                    ServerNet.SendPacket(packet.SessionID(), PACKET_ID_ECHO, bodyData);
                    break;

                default:
                    DevLog.Write(string.Format("[ProcessProcket] Invalid PacketID:{0}", packet.PacketID()), LOG_LEVEL.ERROR);
                    break;
                }
                break;
            }
        }
Beispiel #14
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));
            }
        }
Beispiel #15
0
        public void InnerNotifyLeaveLobby(SFNETPacket packet)
        {
            var notify = JsonEnDecode.Decode <CSCommonLib.JsonPacketInnerNotifyLeaveLobby>(packet.GetData());

            var user = UserManagerRef.GetUser(notify.UserID);

            if (user == null)
            {
                return;
            }

            user.SetLobby(0);

            var response = new JsonPacketResponseLeaveLobby()
            {
                Result = notify.Result
            };

            ServerNetworkRef.Send <JsonPacketResponseLeaveLobby>(user.SessionID, PACKET_ID.RESPONSE_LEAVE_LOBBY, response);
        }
Beispiel #16
0
        public void RequestEnterLobby(SFNETPacket packet)
        {
            try
            {
                var request = JsonEnDecode.Decode <JsonPacketRequestEnterLobby>(packet.GetData());

                // 로비에 추가
                var error = LobbyManagerRef.EnterLobby(request.LobbyID, packet.SessionID(), request.UserID);

                if (error == ERROR_CODE.NONE)
                {
                    InnerMessageQueue.CurrentLobbyUserCount(request.LobbyID, LobbyManagerRef.LobbyCurrentUserCount(request.LobbyID));
                }

                ResponseEnterLobby(error, request.LobbyID, request.UserID);
            }
            catch
            {
            }
        }
Beispiel #17
0
        public void RequestRegistServer(SFNETPacket packetData)
        {
            try
            {
                var request = JsonEnDecode.Decode <JsonPacketRequestReqistServer>(packetData.GetData());

                // 이미 등록된 유저인가? serial, ID
                var result = ServerManagerRef.AddServer(packetData.SessionID(), request.ServerName);

                var response = new JsonPacketResponseReqistServer()
                {
                    Result = result, ServerName = "GameServer"
                };
                ServerNetworkRef.Send <JsonPacketResponseReqistServer>(packetData.SessionID(), PACKET_ID.RESPONSE_REGIST_SERVER, response);

                DevLog.Write(string.Format("result:{0}, ServerName:{1}, SessionID: {2}", result.ToString(), request.ServerName, packetData.SessionID()), LOG_LEVEL.INFO);
                CGSFNETCommon.FileLogger.Info(string.Format("result:{0}, ServerName:{1}, SessionID: {2}", result.ToString(), request.ServerName, packetData.SessionID()));
            }
            catch
            {
            }
        }
Beispiel #18
0
        public void RequestLeaveLobby(SFNETPacket packetData)
        {
            try
            {
                var request = JsonEnDecode.Decode <JsonPacketRequestLeaveLobby>(packetData.GetData());

                var result = LobbyManagerRef.LeaveLobby(request.LobbyID, request.UserID);

                if (packetData.SessionID() >= 0)
                {
                    ResponseLeaveLobby(result, request.LobbyID, request.UserID);
                }

                if (result == ERROR_CODE.NONE)
                {
                    InnerMessageQueue.CurrentLobbyUserCount(request.LobbyID, LobbyManagerRef.LobbyCurrentUserCount(request.LobbyID));
                }
            }
            catch
            {
            }
        }
Beispiel #19
0
        public void InnerNotifyEnterLobby(SFNETPacket packet)
        {
            var notify = JsonEnDecode.Decode <CSCommonLib.JsonPacketInnerNotifyEnterLobby>(packet.GetData());

            var user = UserManagerRef.GetUser(notify.UserID);

            if (user == null)
            {
                var jsonData = new JsonPacketInnerRollBackEnterLobby()
                {
                    LobbyID = notify.LobbyID, UserID = notify.UserID
                };
                var bodyData = CGSFNETCommon.JsonEnDecode.Encode <JsonPacketInnerRollBackEnterLobby>(jsonData);

                var InnerPacket = new CgsfNET64Lib.SFNETPacket();
                InnerPacket.SetData(-1, (ushort)PACKET_ID.INNER_ROLL_BACK_ENTER_LOBBY, bodyData);
                RelayPacketPacketProcess.RelayPacket(notify.LobbyID, InnerPacket);
                return;
            }

            if (notify.Result == ERROR_CODE.NONE)
            {
                user.SetLobby(notify.LobbyID);
            }
            else
            {
                user.SetLobby(0);
            }


            var response = new JsonPacketResponseEnterLobby()
            {
                Result = notify.Result, LobbyID = notify.LobbyID
            };

            ServerNetworkRef.Send <JsonPacketResponseEnterLobby>(user.SessionID, PACKET_ID.RESPONSE_ENTER_LOBBY, response);
        }
Beispiel #20
0
        public void RequestChat(SFNETPacket packetData, ConnectUser user)
        {
            if (user == null)
            {
                return;
            }

            try
            {
                var request = JsonEnDecode.Decode <JsonPacketRequestChat>(packetData.GetData());

                if (user.LobbyID <= 0)
                {
                    ResponseErrorLobbyChat(packetData.SessionID(), ERROR_CODE.LOBBY_CHAT_DO_NOT_ENTER_LOBBY);
                    return;
                }

                LobbyManagerRef.LobbyChat(user.LobbyID, user.ID, request.Chat);
            }
            catch (Exception)
            {
                ResponseErrorLobbyChat(packetData.SessionID(), ERROR_CODE.ERROR);
            }
        }
Beispiel #21
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;
            }
        }