private void UpdateMap() { Call call = new Call(GoogleMapsDriver.DRIVER_ID, "updatePos", null); call.AddParameter("latitude", pos.latitude); call.AddParameter("longitude", pos.longitude); gateway.CallService(gateway.currentDevice, call); call.service = "render"; call.parameters = null; gateway.CallService(gateway.currentDevice, call); }
private void CheckIn() { if (webHost == null) { webHost = gateway.ListDevices().Find(d => d.name == "ubimon-server"); } if (webHost != null) { Call call = new Call(POSITION_REG_DRIVER, "checkIn"); call.AddParameter("clientName", clientName) .AddParameter("latitude", pos.latitude) .AddParameter("longitude", pos.longitude) .AddParameter("delta", pos.delta) .AddParameter("metadata", "ubimon"); Response r = gateway.CallService(webHost, call); if ((r != null) && string.IsNullOrEmpty(r.error)) { myPosRegId = int.Parse(r.GetResponseData("clientId").ToString()); } else { gateway.logger.LogError(r == null ? "No response for check-in." : "Error on check-in: " + r.error); } } }
private void UpdatePositionRegistry() { if (myPosRegId != null) { Call call = new Call(POSITION_REG_DRIVER, "update"); call.AddParameter("clientId", myPosRegId) .AddParameter("latitude", pos.latitude) .AddParameter("longitude", pos.longitude) .AddParameter("delta", pos.delta); Response r = gateway.CallService(webHost, call); if (r == null) { gateway.logger.LogError("No responce to update pos."); } else if (!string.IsNullOrEmpty(r.error)) { gateway.logger.LogError("Update pos error: " + r.error + "."); } else { UpdateNeighbours(); } } else { CheckIn(); } }
private void StationCommand(string command) { peekedUbimon = null; newUbimonIcons = null; Call call = new Call("app", command, "ubimon"); call.AddParameter("playerId", playerId); gateway.CallService(stationDevice, call); if (command.Contains("cursor")) { StationPeek(); } }
private void StationSend() { try { Call call = new Call("app", "store", "ubimon"); call.AddParameter("playerId", playerId); call.AddParameter("ubimon", ubimonContainer.selected.ToString()); Response r = gateway.CallService(stationDevice, call); if ((r != null) && string.IsNullOrEmpty(r.GetResponseString("error"))) { ubimons.RemoveAll(u => u.id.Equals(ubimonContainer.selected.id)); ubimonContainer.icons = ubimonContainer.Fit(ubimons); } else { stationError = (r == null) ? "No response!" : r.GetResponseString("error"); } } catch (System.Exception e) { StationCommand("leave"); stationError = e.ToString(); } }
private void StationReachThread() { while ((mode == Mode.Station) && (stationError == null) && reachingStation) { Call call = new Call("app", "enter", "ubimon"); call.AddParameter("playerId", playerId); try { Response r = gateway.CallService(stationDevice, call); reachingStation = false; if ((r == null) || (!string.IsNullOrEmpty(r.GetResponseString("error")))) { stationError = (r == null) ? "No response!" : r.GetResponseString("error"); } } catch (System.Exception e) { reachingStation = false; stationError = e.ToString(); } } }
private void StationPeek() { peekedUbimon = null; newUbimonIcons = null; Call call = new Call("app", "peek", "ubimon"); call.AddParameter("playerId", playerId); Response r = gateway.CallService(stationDevice, call); string ubimon = r.GetResponseString("ubimon"); if (ubimon != null) { try { peekedUbimon = Ubimon.FromJSON(ubimon, ubimonDB); newUbimonIcons = ubimonContainer.Fit(ubimons, peekedUbimon); } catch (System.Exception e) { StationCommand("leave"); stationError = e.ToString(); } } }
private void UpdateNeighbours() { Call call = new Call(POSITION_REG_DRIVER, "listNeighbours"); call.AddParameter("latitude", pos.latitude) .AddParameter("longitude", pos.longitude) .AddParameter("delta", pos.delta) .AddParameter("range", neighbourSearchRange); Response r = gateway.CallService(webHost, call); if ((r != null) && string.IsNullOrEmpty(r.error)) { try { var list = new List <WorldEntity>(); var clients = (IList <object>)r.GetResponseData("clients"); foreach (var client in clients) { var data = (IDictionary <string, object>)client; int id = UOS.Util.ConvertOrParse <int>(data["id"]); string meta = ""; object metaObj; if (data.TryGetValue("metadata", out metaObj)) { meta = metaObj.ToString().Trim().ToLower(); } if ((id != (int)myPosRegId) && meta.Contains("ubimon")) { WorldEntity e = new WorldEntity(); e.id = id; e.name = data["name"] as string; e.pos = GlobalPosition.FromJSON(data); e.distance = UOS.Util.ConvertOrParse <double>(data["distance"]); object deviceDesc = data["device"]; e.deviceDesc = (deviceDesc is string) ? (string)deviceDesc : MiniJSON.Json.Serialize(deviceDesc); e.type = WorldEntity.Type.Player; if (meta.Contains("station")) { e.type = WorldEntity.Type.Station; } else if (meta.Contains("gathering")) { e.type = WorldEntity.Type.GatheringPoint; } list.Add(e); } } list.Sort((a, b) => a.distance.CompareTo(b.distance)); neighbours = list; } catch (System.Exception e) { ((UnityGateway)uOS.gateway).logger.Log(e.ToString()); } } }