예제 #1
0
    JsonObjectCollection SetProtocol(PROTOCOL protocl)
    {
        JsonObjectCollection jsonObj = new JsonObjectCollection();

        jsonObj.Add(new JsonStringValue("PROTOCOL_ID", protocl.ToString()));
        return(jsonObj);
    }
예제 #2
0
        public void process_user_operation(CPacket msg)
        {
            PROTOCOL protocol = (PROTOCOL)msg.pop_protocol_id();

            Console.WriteLine("protocol :" + protocol.ToString());
            switch (protocol)
            {
            case PROTOCOL.REQ_ROOMLIST:
            {
                var RoomList = Utility.Utility.GameRoomManager.GetGameRooms();

                var packet = Utility.Utility.DictionaryToRoomList(RoomList);

                send(packet);
            }
            break;

            case PROTOCOL.REQ_MAKINGROOM:
            {
            }
            break;

            case PROTOCOL.REQ_ENTERROOM:
            {
            }
            break;

            case PROTOCOL.REQ_STARTGAME:
            {
            }
            break;
            }
        }
예제 #3
0
        private JObject SetProtocol(PROTOCOL protocl)
        {
            JObject jsonObj = new JObject();

            jsonObj.Add("PROTOCOL_ID", protocl.ToString());
            return(jsonObj);
        }
예제 #4
0
    /// <summary>
    /// 스크립트로 가장먼저 서버의 ack 를 받는 코드
    /// </summary>
    /// <param name="Ans"></param>
    public void Receiver(JSONObject jsonObject, NetCallBack callback)
    {
        PROTOCOL protocol = (PROTOCOL)jsonObject["cmd"].n;

        Debug.Log(protocol + ": " + jsonObject.ToString());

        int errno = (int)jsonObject["errno"].n;

        if (errno == 0)
        {
            switch (protocol)
            {
            case PROTOCOL.P_SERVICE_INFO:
                P_SERVICE_INFO(jsonObject);
                break;

            case PROTOCOL.P_USER_LOGIN:
                P_USER_LOGIN(jsonObject);
                break;

            case PROTOCOL.P_USER_INFO:
                P_USER_INFO(jsonObject);
                break;

            case PROTOCOL.P_USER_LIST:
                P_USER_LIST(jsonObject);
                break;

            case PROTOCOL.P_USER_SETPW:
                P_USER_SETPW(jsonObject);
                break;

            case PROTOCOL.P_USER_UPGRADE:
                P_USER_UPGRADE(jsonObject);
                break;

            case PROTOCOL.P_USER_NOTIFY:
                P_USER_NOTIFY(jsonObject);
                break;

            case PROTOCOL.P_USER_NICKNAME:
                P_USER_NICKNAME(jsonObject);
                break;

            case PROTOCOL.P_GAME_START:
                P_GAME_START(jsonObject);
                break;

            case PROTOCOL.P_GAME_RESULT:
                P_GAME_RESULT(jsonObject);
                break;

            case PROTOCOL.P_GAME_LOG:
                P_GAME_LOG(jsonObject);
                break;

            case PROTOCOL.P_GAME_REVENGE:
                P_GAME_REVENGE(jsonObject);
                break;

            default:
                Debug.LogError("not found protocol");
                break;
            }
        }
        else
        {
            // 팝업으로 에러 띄움
            //ShowErrorPopup(errno);
            UIManager.instance.CreateOKPopup(errno);
            Debug.Log("ErrNo : " + protocol.ToString() + "(" + errno + ")");
        }

        if (callback != null)
        {
            callback(jsonObject);
        }
    }
예제 #5
0
        void IPeer.process_user_operation(CPacket msg)
        {
            PROTOCOL protocol = (PROTOCOL)msg.pop_protocol_id();

            Console.WriteLine("protocol :" + protocol.ToString());
            switch (protocol)
            {
            case PROTOCOL.REQ_ROOMLIST:
            {
                var RoomList = Utility.Utility.GameRoomManager.GetGameRooms();

                var packet = Utility.Utility.DictionaryToRoomList(RoomList);

                send(packet);

                CPacket.destroy(packet);
            }
            break;

            case PROTOCOL.REQ_MAKINGROOM:
            {
                CPacket packet = CPacket.create((short)PROTOCOL.DEC_MAKINGROOM);

                string ID    = msg.pop_string();
                string title = msg.pop_string();
                string IP    = msg.pop_string();

                if (Utility.Utility.GameRoomManager.MakingRoom(ID, title, IP))
                {
                    packet.push(1);
                }
                else
                {
                    packet.push(0);
                }

                send(packet);

                CPacket.destroy(packet);
            }
            break;

            case PROTOCOL.REQ_ENTERROOM:
            {
                CPacket packet = CPacket.create((short)PROTOCOL.DEC_ENTERROOM);

                string MasterID = msg.pop_string();
                string ID       = msg.pop_string();
                string IP       = msg.pop_string();
                var    Room     = Utility.Utility.GameRoomManager.FindRoom(MasterID);

                if (Room != null)
                {
                    packet.push(1);
                    Room.JoinRoom(NoTitleGameServer.Database.UserManager.FindUser(ID), IP);
                }
                else
                {
                    packet.push(0);
                }

                send(packet);

                CPacket.destroy(packet);
            }
            break;

            case PROTOCOL.REQ_STARTGAME:
            {
                CPacket packet = CPacket.create((short)PROTOCOL.DEC_STARTGAME);

                string ID   = msg.pop_string();
                var    room = Utility.Utility.GameRoomManager.FindRoom(ID);

                if (room != null && room.CanStartGame())
                {
                    packet.push(1);
                    room.BroadCast(packet);
                }
                else
                {
                    packet.push(0);
                    send(packet);
                }

                CPacket.destroy(packet);
            }
            break;

            case PROTOCOL.REQ_REGISTER:
            {
                var ID   = msg.pop_string();
                var PW   = msg.pop_string();
                var Name = msg.pop_string();

                var Error = new RegisterFailure();
                var flag  = Database.UserManager.AddUser(ID, PW, Name, ref Error);

                CPacket packet = CPacket.create((short)PROTOCOL.DEC_REGISTER);
                packet.push((byte)(flag ? 1 : 0));
                packet.push_int16((short)Error);

                send(packet);

                CPacket.destroy(packet);
            }
            break;

            case PROTOCOL.REQ_LOGIN:
            {
                var ID = msg.pop_string();
                var PW = msg.pop_string();

                var Error = new LoginFailure();
                var user  = Database.UserManager.FindUser(ID);

                CPacket packet = CPacket.create((short)PROTOCOL.DEC_LOGIN);

                if (user.PW == PW)
                {
                    packet.push(1);

                    user.token = token;
                }
                else
                {
                    packet.push(0);
                    Error = Error | LoginFailure.PW_INCORRECT;
                    if (user.ID == null)
                    {
                        Error = Error | LoginFailure.ID_INCORRECT;
                    }
                    packet.push_int16((short)Error);
                }

                send(packet);

                CPacket.destroy(packet);
            }
            break;

            case PROTOCOL.REQ_NICKNAME:
            {
                CPacket packet = CPacket.create((short)PROTOCOL.SEND_NICKNAME);
                packet.push(Database.UserManager.FindUser(msg.pop_string()).Name);

                send(packet);

                CPacket.destroy(packet);
            }
            break;
            }
            CPacket.destroy(msg);
        }