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); }
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; } } }
public void P_Connection_Lost(ARWServer server, ARWObject obj) { server.isConnected = false; if (ARWEvents.CONNECTION_LOST.handler != null) { ARWEvents.CONNECTION_LOST.handler(obj); } }
public void P_Disconnection(ARWServer server, ARWObject obj) { server.isConnected = false; if (ARWEvents.DISCONNECTION.handler != null) { ARWEvents.DISCONNECTION.handler(obj); } }
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); }
private void SendReqeust(ARWObject arwObject) { if (arwObject == null) { return; } byte[] bytesToSend = arwObject.Compress(); client.Client.Send(bytesToSend); }
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); } }
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); } }
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); }
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); } }
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); } }
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; } }
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); } }
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(); }
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(); }
public void P_User_Variable_Update(ARWServer server, ARWObject obj) { }