コード例 #1
0
        public static ARWObject Extract(byte[] bytes)
        {
            string data = System.Text.Encoding.UTF8.GetString(bytes).Replace("\0", null).Replace("\"", null);

            ARWObject newObj = new ARWObject();

            string[] dataParts = data.Split('~');
            if (dataParts.Length == 3)
            {
                newObj.requestName = dataParts [0];

                string[] prms = dataParts [1].Split('_');
                foreach (string p in prms)
                {
                    string[] paramParts = p.Split('#');
                    if (paramParts.Length == 2)
                    {
                        newObj.dataList.Add(paramParts [0], paramParts [1]);
                    }
                }

                newObj.eventParams = SpecialEventParam.Extract(dataParts [2]);
                return(newObj);
            }
            return(newObj);
        }
コード例 #2
0
        private void HandleRequest(string data)
        {
            ARWObject newObj       = ARWObject.Extract(data);
            ARWEvent  currentEvent = ARWEvents.allEvents.Where(a => a.eventName == newObj.GetRequestName()).FirstOrDefault();

            if (currentEvent != null)
            {
                if (currentEvent.p_handler != null)
                {
                    currentEvent.p_handler(this, newObj);
                }
                else
                {
                    if (currentEvent.handler != null)
                    {
                        currentEvent.handler(newObj);
                    }
                }
            }
            else
            {
                wrongData += data;

                if (ARWObject.CanBeARWObject(wrongData))
                {
                    wrongData += data;
                    HandleRequest(wrongData);
                    wrongData = "";
                    return;
                }
            }
        }
コード例 #3
0
 public void P_Connection_Lost(ARWServer server, ARWObject obj)
 {
     server.isConnected = false;
     if (ARWEvents.CONNECTION_LOST.handler != null)
     {
         ARWEvents.CONNECTION_LOST.handler(obj);
     }
 }
コード例 #4
0
 public void P_Disconnection(ARWServer server, ARWObject obj)
 {
     server.isConnected = false;
     if (ARWEvents.DISCONNECTION.handler != null)
     {
         ARWEvents.DISCONNECTION.handler(obj);
     }
 }
コード例 #5
0
        public Room P_Room_Create(ARWServer server, ARWObject obj)
        {
            Room newRoom = new Room(obj.eventParams);

            ARWServer.allRooms.Add(newRoom);

            Console.WriteLine("Room Create : " + newRoom.name + " : " + newRoom.tag + " : " + newRoom.GetUserList().Length);
            return(newRoom);
        }
コード例 #6
0
        private void SendReqeust(ARWObject arwObject)
        {
            if (arwObject == null)
            {
                return;
            }

            byte[] bytesToSend = arwObject.Compress();
            client.Client.Send(bytesToSend);
        }
コード例 #7
0
        public void P_Login(ARWServer server, ARWObject obj)
        {
            User me = new User(obj.eventParams);

            server.me = me;

            if (ARWEvents.LOGIN.handler != null)
            {
                ARWEvents.LOGIN.handler(obj);
            }
        }
コード例 #8
0
        public void P_Extension_Handler(ARWServer server, ARWObject obj)
        {
            string cmd = obj.eventParams.GetString("cmd");

            ExtensionRequest req = ARWEvents.extensionRequests.Where(a => a.cmd == cmd).FirstOrDefault();

            if (req != null)
            {
                req.handler(obj);
            }
        }
コード例 #9
0
        public static bool CanBeARWObject(string data)
        {
            ARWObject newObj       = ARWObject.Extract(data);
            ARWEvent  currentEvent = ARWEvents.allEvents.Where(a => a.eventName == newObj.GetRequestName()).FirstOrDefault();

            if (currentEvent == null)
            {
                return(false);
            }

            return(true);
        }
コード例 #10
0
        public void P_Join_Room(ARWServer server, ARWObject obj)
        {
            Room currentRoom = P_Room_Create(server, obj);

            User currentUser = server.me;

            server.me.lastJoinedRoom = currentRoom;

            currentRoom.AddUser(currentUser);

            if (ARWEvents.ROOM_JOIN.handler != null)
            {
                ARWEvents.ROOM_JOIN.handler(obj);
            }
        }
コード例 #11
0
        public void P_Connection(ARWServer server, ARWObject obj)
        {
            DateTime t = DateTime.Parse(obj.GetString("serverTime"));

            server.SetServerTime(t);

            if (obj.GetString("error") == "")
            {
                server.isConnected = true;
            }

            if (ARWEvents.CONNECTION.handler != null)
            {
                ARWEvents.CONNECTION.handler(obj);
            }
        }
コード例 #12
0
        public void Connect()
        {
            client = new TcpClient();
            try{
                this.firstDateTime = DateTime.Now;
                client.Connect(host, tcpPort);
                ARWObject newObj = new ARWObject();
                newObj.SetRequestName(ARWServer_CMD.Connection_Success);

                Thread t = new Thread(() => SendReqeust(newObj));
                t.Start();
            }catch (System.Net.Sockets.SocketException e) {
                ARWObject obj = new ARWObject();
                obj.PutString("error", e.Message);
                ARWEvents.CONNECTION.p_handler(this, obj);
                return;
            }
        }
コード例 #13
0
        public void P_User_Enter_Room(ARWServer server, ARWObject obj)
        {
            User joinedUser = new User(obj.eventParams);

            Room currentRoom = ARWServer.allRooms.Where(a => a.name == obj.eventParams.GetString("RoomName")).FirstOrDefault();

            try{
                currentRoom.AddUser(joinedUser);
            }catch (NullReferenceException) {
                Debug.LogError("Room not exist : " + obj.eventParams.GetString("RoomName"));
                return;
            }

            if (ARWEvents.USER_ENTER_ROOM.handler != null)
            {
                ARWEvents.USER_ENTER_ROOM.handler(obj);
            }
        }
コード例 #14
0
        public void SendLoginRequest(string userName, ARWObject arwObject)
        {
            ThreadStart threadFunc = new ThreadStart(delegate() {
                ARWObject loginObj = arwObject;
                if (loginObj == null)
                {
                    loginObj = new ARWObject();
                }

                loginObj.SetRequestName(ARWServer_CMD.Login);
                loginObj.eventParams.PutVariable("userName", userName);

                Thread t = new Thread(() => SendReqeust(loginObj));
                t.Start();
            });
            Thread loginThread = new Thread(threadFunc);

            loginThread.Start();
        }
コード例 #15
0
        public void SendExtensionRequest(string cmd, ARWObject arwObj, bool room = false, bool isTcp = true)
        {
            if (arwObj == null)
            {
                arwObj = new ARWObject();
            }

            arwObj.eventParams.PutVariable("cmd", cmd);
            arwObj.eventParams.PutVariable("isRoomRequest", room);

            if (room)
            {
                arwObj.eventParams.PutVariable("roomId", me.lastJoinedRoom.id);
            }

            arwObj.SetRequestName(ARWServer_CMD.Extension_Request);

            Thread t = new Thread(() => SendReqeust(arwObj));

            t.Start();
        }
コード例 #16
0
 public void P_User_Variable_Update(ARWServer server, ARWObject obj)
 {
 }