///////////////////////////////////////////////////////////////////////////////////////////// #region // Private Methods private IMessage PerformGet(IMessage request) { ISpace ts = this.repository.GetSpace(request.Target); if (ts != null) { GetRequest getReq = (GetRequest)request; ITuple tuple = ts.Get(new Pattern(getReq.Template)); return(new GetResponse(request.Source, request.Session, request.Target, tuple?.Fields ?? null, StatusCode.OK, StatusMessage.OK)); } return(new GetResponse(request.Source, request.Session, request.Target, null, StatusCode.NOT_FOUND, StatusMessage.NOT_FOUND)); }
private void Stream() { var collector = new TupleCollector(space); space.Query("start"); space.Get("lobby_lock"); Console.WriteLine("Starting game data streaming"); while (true) { collector.Collect(); } }
public static bool Join(string username) { Console.WriteLine("Validate username"); ISpace space = Connection.GlobalSpace; // Get lock space.Get("newuser_lock"); space.Put("user", username); Tuple result = (Tuple)space.Get("connected", typeof(bool), typeof(int)); if ((bool)result[1]) { Console.WriteLine("Join succesfull"); Connection.LocalPlayer = new Player((uint)(int)result[2], username); space.Put("newuser_lock"); return(true); } else { space.Put("newuser_lock"); return(false); } }
/// <summary> /// Collects Tuples matching {<"components", typeof(string), typeof(string)">} /// This method will upload the components and earlier versions of the same upload based on the second tuple element. This elements (Tuple[1]) /// is expected to be a version number convertet to a string. /// </summary> public void Collect() { //Collecting components uploaded from clients var tuple = space.Get("components", typeof(string), typeof(string)); string updateId = (string)tuple[1]; string jsonData = (string)tuple[2]; JArray jarray = JsonConvert.DeserializeObject <JArray>(jsonData); // Fetch client in order to remove all id components from the space var id = (int)jarray.First.SelectToken("client_id"); foreach (JToken jToken in jarray) { UpdatorJToken(jToken, updateId); } RemoveExistingClientTuples(id, updateId); }