public string[] OnDataRecieved(int cnnId, string[] data) { if (data == null) { return(null); } switch (data[0]) { case "INIT": //OnInit(cnnId, 1); OnConnection(cnnId); break; case "NAMEIS": OnNameIs(cnnId, data[1]); break; case "GRABOBJECT": objects.SetObjectPlace(int.Parse(data[2]), stringToVec(data[3]), stringToQuat(data[4])); connection.Send("GRABBED|" + data[1] + "|" + data[2] + "|" + data[3] + "|" + data[4], connection.unreliable, clientIds); break; case "MYPOS": string[] d = data[1].Split('$'); players[cnnId].setPlayerData(stringToVec(d[0]), stringToVec(d[1]), stringToVec(d[2])); break; case "RESOLVING": if (lvlgenerator.roomsData[int.Parse(data[1])].neededResult == 1) { //rooms.OnDoorOpen(int.Parse(data[1]), 1); connection.Send("RESOLVED|" + data[1] + "|" + "1", connection.reliable, clientIds); } else { if (!playersImageRoomResolved.ContainsKey(cnnId)) { playersImageRoomResolved.Add(cnnId, 1); if (playersImageRoomResolved.Count == lvlgenerator.roomsData[int.Parse(data[1])].neededResult) { connection.Send("RESOLVED|" + data[1] + "|" + "1", connection.reliable, clientIds); } } } break; case "NOTRESOLVING": if (playersImageRoomResolved.ContainsKey(cnnId)) { playersImageRoomResolved.Remove(cnnId); } break; default: // Not server case Handling return(data); } Debug.Log("Server recieved from: " + cnnId + " message: " + string.Join("|", data)); return(null); }
public string[] OnDataRecieved(string[] data) { if (data == null) { return(null); } if (!data[0].Equals("ASKPOS")) { Debug.Log("Client: " + hostId + " recieved: " + string.Join("|", data)); } switch (data[0]) { case "ASKPOS": if (!isStarted) { return(null); } string msg = "MYPOS|" + players.setPlayersPosition(data); connection.Send(msg, connection.unreliable, hostId); break; case "CONNECTED": connection.Send("INIT", connection.reliable, hostId); break; case "ASKNAME": OnAskName(data); break; case "CNN": players.SpawnPlayer(data[1], int.Parse(data[2])); isStarted = true; break; case "DC": players.PlayerDisconnected(int.Parse(data[1])); break; /*case "MOVABLEOBJ": * for (int i = 1; i < data.Length; i++) * { * string[] d = data[i].Split('%'); * Debug.Log(data[i]); * objects.SpawnObjects(int.Parse(d[0]), Instantiate(Resources.Load<GameObject>(d[1]), stringToVec(d[2]), stringToQuat(d[3]))); * } * break;*/ case "OBJECTS": for (int i = 2; i < data.Length; i++) { string[] d = data[i].Split('%'); Debug.Log(data[i]); GameObject o = Instantiate(Resources.Load <GameObject>(d[0])); o.transform.position = stringToVec(d[1]); o.transform.localScale = stringToVec(d[2]); o.transform.rotation = stringToQuat(d[3]); } break; /*case "MOVEOBJECT": * for (int i = 1; i < data.Length; i++) * { * string[] d = data[i].Split('%'); * Debug.Log(data[i]); * objects.SetObjectPlace(int.Parse(d[0]), stringToVec(d[1]), stringToQuat(d[2])); * } * break;*/ case "TEXT": { string[] d = data[2].Split('%'); Debug.Log(data[2]); GameObject t = Instantiate(Resources.Load <GameObject>("Prefabs/TextOutput")); t.transform.position = stringToVec(d[1]); t.transform.SetParent(rooms.GetRoom(int.Parse(data[1])).transform); t.GetComponentInChildren <Text>().text = d[0]; } break; case "GRABBED": objects.SetObjectPlace(int.Parse(data[2]), stringToVec(data[3]), stringToQuat(data[4])); break; case "LOCK": OnLockDataRecieved(data); break; case "RESOLVED": Debug.LogWarning("Recieved message: " + string.Join("|", data)); rooms.OnDoorOpen(int.Parse(data[1]), int.Parse(data[2])); break; default: Debug.LogWarning("Invalid message: " + string.Join("|", data)); break; } //Debug.Log("Cliens: " + hostId + " recieved from Server message: " + string.Join("|", data)); return(null); }