public void sendDataGame(JSONClass ojbect) { GameTransportPacket gameTransportPacket = new GameTransportPacket(); gameTransportPacket.pid = GameApplication.user.id; gameTransportPacket.tableid = tableId; byte[] gdata = getBytes(ojbect.ToString()); gameTransportPacket.gamedata = gdata; sendPacket(gameTransportPacket); }
public void handleBallsUpdate(GameTransportPacket data) { string jsonGameTransportPacket = System.Text.Encoding.UTF8.GetString(data.gamedata); Debug.Log("GameTransportPacket: " + jsonGameTransportPacket); var gameData = JSONNode.Parse(jsonGameTransportPacket); string evt = gameData ["evt"]; if (evt == "startshoot") { gameState = GAMESTATE.WAIT; foreach (GameObject GO in GOS) { string ballname = GO.name; Ball ball = GOSDict[ballname]; ball.orgx.Clear(); ball.orgx.Add(GO.transform.position.x); ball.orgy.Clear(); ball.orgy.Add(GO.transform.position.y); ball.destx.Clear(); ball.desty.Clear(); ball.st.Clear(); } } else if (evt == "balls") { foreach (GameObject GO in GOS) { string ballname = GO.name; float x = gameData[ballname + "x"].AsFloat; float y = gameData[ballname + "y"].AsFloat; bool st = gameData[ballname + "st"].AsBool; // GO.SetActive(st); Ball ball = GOSDict[ballname]; ball.destx.Add(x); ball.desty.Add(y); ball.st.Add(st); if (ball.destx.Count > 1) { ball.orgx.Add(ball.destx[ball.destx.Count - 2]); ball.orgy.Add(ball.desty[ball.desty.Count - 2]); } } } else if (evt == "endshoot") { gameState = GAMESTATE.REPLAY; } }
private void sendPacket(ProtocolObject protocolObject) { Debug.Log("---------> send: " + protocolObject.ToString()); byte[] buffer = serializer.pack(protocolObject); socket.Send(buffer, 0, buffer.Length, SocketFlags.None); if (protocolObject is ServiceTransportPacket) { ServiceTransportPacket sp = (ServiceTransportPacket)protocolObject; string serviceData = System.Text.Encoding.UTF8.GetString(sp.servicedata); Debug.Log("send: " + serviceData); } if (protocolObject is GameTransportPacket) { GameTransportPacket gp = (GameTransportPacket)protocolObject; string gameData = System.Text.Encoding.UTF8.GetString(gp.gamedata); Debug.Log("send: " + gameData); } }
public static void handleGameTransportPacket(GameTransportPacket data) { CubeiaClient cubeia = GameApplication.cubeia; cubeia.tableId = data.tableid; string jsonGameTransportPacket = System.Text.Encoding.UTF8.GetString(data.gamedata); Debug.Log("GameTransportPacket: " + jsonGameTransportPacket); var gameData = JSONNode.Parse(jsonGameTransportPacket); string evt = gameData ["evt"]; if (evt.Equals("ctable")) { var jsonData = new JSONClass(); jsonData ["evt"] = "play"; jsonData ["data"] = "nguyenhaian"; cubeia.sendDataGame(jsonData); } else if (evt.Equals("play")) { // String str = ""; // foreach (byte b in data.gamedata) // str += (byte)b + ", "; // // Debug.LogWarning(str); // Debug.LogWarning("length: "+data.gamedata.Length); // sendPacket(data); } else if (evt.Equals("ltable")) { // khi gui ltable len, neu tra ve LeaveResponsePacket thi back ra LobbyScene // truong hop khac thi tra ve ten nguoi thoat ban choi // => day nguoi do ra khoi ban choi } }