void OnRelayMessage(short netId, byte[] jsonResponse) { var memberCxId = m_bcWrapper.RelayService.GetCxIdForNetId(netId); string jsonMessage = Encoding.ASCII.GetString(jsonResponse); var json = JsonReader.Deserialize <Dictionary <string, object> >(jsonMessage); foreach (var member in State.lobby.members) { if (member.cxId == memberCxId) { var op = json["op"] as string; if (op == "move") { var data = json["data"] as Dictionary <string, object>; member.isAlive = true; member.pos.X = (int)data["x"]; member.pos.Y = (int)data["y"]; } else if (op == "shockwave") { var data = json["data"] as Dictionary <string, object>; var shockwave = new Shockwave(); shockwave.pos.X = (int)data["x"]; shockwave.pos.Y = (int)data["y"]; shockwave.colorIndex = member.colorIndex; shockwave.startTime = DateTime.Now; State.shockwaves.Add(shockwave); } break; } } }
// User clicked mouse in the play area public void Shockwave(Point pos) { // Send to other players Dictionary <string, object> jsonData = new Dictionary <string, object>(); jsonData["x"] = pos.X; jsonData["y"] = pos.Y; Dictionary <string, object> json = new Dictionary <string, object>(); json["op"] = "shockwave"; json["data"] = jsonData; byte[] data = Encoding.ASCII.GetBytes(JsonWriter.Serialize(json)); m_bcWrapper.RelayService.Send(data, BrainCloudRelay.TO_ALL_PLAYERS, true, // Reliable false, // Unordered Settings.sendChannel); // Create a local shockwave so we can see it var shockwave = new Shockwave(); shockwave.pos = pos; shockwave.colorIndex = State.user.colorIndex; shockwave.startTime = DateTime.Now; State.shockwaves.Add(shockwave); }