public void SaveCurMaxUserID(long userId) { var info = new UserIdInfo() { Name = "Unique", Id = userId }; _userIds.Update(info); }
public long GetCurMaxUserID() { var info = _userIds.FindOne(a => a.Name == "Unique"); if (info == null) { info = new UserIdInfo() { Name = "Unique", Id = 0 }; _userIds.Insert(info); } return(info.Id); }
public static RemovableListItem <string> UserIdInfoToRemovableListItemVM(UserIdInfo info, Action <string> removeAction) { var roundedDesc = info.Description.Substring(0, Math.Min(info.Description.Length - 1, 10)); return(new RemovableListItem <string>(info.UserId, $"{info.UserId} | {roundedDesc}", removeAction)); }
public void CreateLobby() { // Get center of lobby GPS.getCenter(); GPS.centerFound = true; Players(); TimeLimit(); username = PlayerPrefs.GetString("Name", "Guest"); latitude = GPS.latCenter; longitude = GPS.lonCenter; PlayerPrefs.SetFloat("HLong", longitude); PlayerPrefs.SetFloat("HLat", latitude); PlayerPrefs.SetInt("Host", 1); LobbiesInfo lobbyInfo = new LobbiesInfo(username, timer, player_count, latitude, longitude); // Create JSON out of info string jsonPayload = JsonConvert.SerializeObject(lobbyInfo); // Make HttpWebRequest to AddUser page HttpWebRequest request = WebRequest.Create("http://cop4331project.com/AddLobbies.php") as HttpWebRequest; // Set type to JSON and method to post request.ContentType = "application/json"; request.Method = "POST"; // Send JSON to php file using (var streamWriter = new StreamWriter(request.GetRequestStream())) { streamWriter.Write(jsonPayload); streamWriter.Flush(); streamWriter.Close(); } string result; // Response variable holds response from JSON HttpWebResponse response = request.GetResponse() as HttpWebResponse; // Save string from JSON to result using (var streamReader = new StreamReader(response.GetResponseStream())) { result = streamReader.ReadToEnd(); } // Convert JSON into instance of UserInfo type UserIdInfo userInfo = JsonConvert.DeserializeObject <UserIdInfo>(result); PlayerPrefs.SetInt("Lobby", userInfo.Host_Lobby_id[0]); // NOW JOIN THE LOBBY // Create JoinInfo instance with username and hashed password JoinInfo jsonInfo = new JoinInfo(userInfo.Host_Lobby_id[0].ToString(), PlayerPrefs.GetString("Name"), PlayerPrefs.GetInt("ID"), 0); // Create JSON out of info string jsonPayload2 = JsonConvert.SerializeObject(jsonInfo); // Make HttpWebRequest to Login page HttpWebRequest request2 = WebRequest.Create("http://cop4331project.com/AddLobby.php") as HttpWebRequest; // Set type to JSON and method to post request2.ContentType = "application/json"; request2.Method = "POST"; // Send JSON to php file using (var streamWriter2 = new StreamWriter(request2.GetRequestStream())) { streamWriter2.Write(jsonPayload2); streamWriter2.Flush(); streamWriter2.Close(); } }
public void CreateLobby() { // Get center of lobby //GPS.Instance.getCenter(); //GPS.Instance.centerFound = true; lobby = PlayerPrefs.GetInt("Lobby", 0); id = PlayerPrefs.GetInt("ID", 0); username = PlayerPrefs.GetString("Name", "Guest"); timer = PlayerPrefs.GetInt("Time Limit", 15); latitude = PlayerPrefs.GetFloat("HLat", 0); longitude = PlayerPrefs.GetFloat("HLong", 0); //timer = 15; player_count = PlayerPrefs.GetInt("", 0); //LobbiesInfo info2 = new LobbiesInfo(user, timer, player_count, GPS.Instance.latCenter, GPS.Instance.lonCenter); LobbiesInfo info2 = new LobbiesInfo(username, timer, player_count, latitude, longitude); // Create JSON out of info string jsonPayload2 = JsonConvert.SerializeObject(info2); // Make HttpWebRequest to AddUser page HttpWebRequest request2 = WebRequest.Create("http://cop4331project.com/AddLobbies.php") as HttpWebRequest; // Set type to JSON and method to post request2.ContentType = "application/json"; request2.Method = "POST"; // Send JSON to php file using (var streamWriter2 = new StreamWriter(request2.GetRequestStream())) { streamWriter2.Write(jsonPayload2); streamWriter2.Flush(); streamWriter2.Close(); } string result2; // Response variable holds response from JSON HttpWebResponse response2 = request2.GetResponse() as HttpWebResponse; // Save string from JSON to result using (var streamReader2 = new StreamReader(response2.GetResponseStream())) { result2 = streamReader2.ReadToEnd(); } // Convert JSON into instance of UserInfo type UserIdInfo userInfo = JsonConvert.DeserializeObject <UserIdInfo>(result2); lobby = userInfo.Host_Lobby_id[0]; freddy = 0; // Create UserInfo instance with username and hashed password UserInfo info = new UserInfo(lobby, id, username, freddy); // Create JSON out of info string jsonPayload = JsonConvert.SerializeObject(info); // Make HttpWebRequest to AddUser page HttpWebRequest request = WebRequest.Create("http://cop4331project.com/AddLobby.php") as HttpWebRequest; // Set type to JSON and method to post request.ContentType = "application/json"; request.Method = "POST"; // Send JSON to php file using (var streamWriter = new StreamWriter(request.GetRequestStream())) { streamWriter.Write(jsonPayload); streamWriter.Flush(); streamWriter.Close(); } }