/// <summary> /// Update the steam token of the program used to communicate with steam /// </summary> private static void UpdateSteamToken() { var msg = new StdData("", Program.HostId, 2000); var rec = new StdData(CustomSocket.StartClient(msg.Data)); if (rec.PacketType == 2000) { Program.SteamToken = rec.Text; } }
/// <summary> /// Asks the server for a new host id /// </summary> public static void UpdateHostId() { var msg = new StdData("", Program.HostId, 2001); var rec = new StdData(CustomSocket.StartClient(msg.Data)); if (rec.PacketType == 2001) { ushort.TryParse(rec.Text, out Program.HostId); } Console.WriteLine("New host id has been assigned: " + Program.HostId); }
/// <summary> /// Shows the general statistics for the server(The total stats for the tables) /// </summary> public static void ShowGenStats() { while (true) { if (Program.HostId == 0) { Console.Clear(); Updater.UpdateHostId(); Thread.Sleep(1000); } Console.Clear(); Console.WriteLine("Server IP: " + Program.IpAddress + " Port: " + Program.Port + " HostId: " + Program.HostId); Console.WriteLine(); Console.WriteLine("Getting the information from the server"); var information = new StdData(CustomSocket.StartClient(new StdData("", Program.HostId, 2050).Data)).Text; Console.WriteLine(information); Console.WriteLine("1. Refresh"); Console.WriteLine("2. Exit"); var o = Console.ReadLine(); if (o == "1") { continue; } break; } }
/// <summary> /// Will cycle through all of the functions, updating what is needed /// </summary> public static void UpdateAll() { UpdateHostId(); UpdateSteamToken(); Console.Clear(); while (Console.KeyAvailable == false) { Thread.Sleep(1000); Console.WriteLine("Server IP: " + Program.IpAddress + " Port: " + Program.Port + " HostId: " + Program.HostId); var packet = CustomSocket.StartClient(new StdData("", Program.HostId, 2002).Data); switch (new StdData(packet).PacketType) { case 2003: Console.WriteLine("Updating player summaries"); UpdatePlayerSum(new ListOfId(packet).List); break; case 2004: Console.WriteLine("Updating player games"); UpdatePlayerGames(new ListOfId(packet).List); break; case 2006: Console.WriteLine("Updating player friends"); UpdatePlayerFriends(new ListOfId(packet).List); break; default: Console.WriteLine("Nothing to update, waiting 30 seconds"); Thread.Sleep(30000); break; } } }
/// <summary> /// Shows the general player statistics and gives options /// </summary> public static void ShowPlayerStats() { Console.Clear(); while (true) { if (Program.HostId == 0) { Console.Clear(); Updater.UpdateHostId(); Thread.Sleep(1000); } Console.WriteLine("Server IP: " + Program.IpAddress + " Port: " + Program.Port + " HostId: " + Program.HostId); Console.WriteLine(); Console.WriteLine("Please enter either your username or steam id"); var player = Console.ReadLine(); var playerInfo = new ListOfUsers(CustomSocket.StartClient(new StdData(player, Program.HostId, 2051).Data)); var user = new User(); switch (playerInfo.List.Count) { case 0: Console.WriteLine("Username/Id not found, would you like to add it to our database"); Console.WriteLine("1. Yes"); Console.WriteLine("2. Try Again"); Console.WriteLine("3. Exit"); var option = Console.ReadLine(); switch (option) { case "1": UInt64 steamId; while (!UInt64.TryParse(player, out steamId)) { Console.WriteLine("Please re-enter the steam id or type e to exit"); player = Console.ReadLine(); if (player == "e") { return; } } CustomSocket.StartClient(new StdData(steamId.ToString(), Program.HostId, 4000).Data); Console.WriteLine( "The user has been entered into the database, may take a little while to start getting information about the new user"); Console.WriteLine("Returning in 5 seconds"); break; case "2": continue; case "3": return; } break; case 1: user = playerInfo.List[0]; break; default: Console.WriteLine("Multiple users have been detected, please select the one that you would like"); for (var i = 0; i < playerInfo.List.Count; i++) { Console.WriteLine("{0}. {1} {2}", i + 1, playerInfo.List[i].SteamId, playerInfo.List[i].UserName); } var o = Console.ReadLine(); Int16 id; if (Int16.TryParse(o, out id)) { user = playerInfo.List[id - 1]; } break; } Console.SetBufferSize(80, 1000); Console.Clear(); Console.WriteLine("Steam ID: {0}", user.SteamId); Console.WriteLine("UserName: {0}", user.UserName); Console.WriteLine("Profile URL: http://steamcommunity.com/{0}", user.CustomUrl == "/" ? "profiles/" + user.SteamId.ToString() : "id/" + user.CustomUrl); Console.WriteLine("VisibilityState: {0}", user.VisibilityState); if (user.VisibilityState) { Console.WriteLine("Location: {0}", user.Location); Console.WriteLine("Real Name: {0}", user.RealName); Console.WriteLine("Member since: {0}", user.MemberSince); Console.WriteLine("Last Game Update: {0}", user.LastGameUpdate); Console.WriteLine("Last Friend Update: {0}", user.LastFriendUpdate); } Console.WriteLine("Last Summary Update: {0}", user.LastSummaryUpdate); Console.WriteLine("Last Log Off: {0}", user.LastLogOff); if (user.ListOfGames.Count > 0) { Console.WriteLine("List of games:"); int i; for (i = 0; i < user.ListOfGames.Count; i++) { Console.WriteLine("{0}. {1}", i + 1, user.ListOfGames[i].Name ?? user.ListOfGames[i].AppId.ToString()); } Console.WriteLine("{0}. Exit", i + 1); } else { Console.WriteLine("1. Exit"); } // Do all of the menu stuff if (Console.ReadLine() == "1") { return; } Console.ReadLine(); } }
/// <summary> /// Get the steam ids from the server then check their summaries /// </summary> public static bool UpdatePlayerSum(List <ulong> listOfIds) { if (Program.HostId == 0) { Console.Clear(); UpdateHostId(); Thread.Sleep(1000); Console.Clear(); Console.WriteLine("Server IP: " + Program.IpAddress + " Port: " + Program.Port + " HostId: " + Program.HostId); Console.WriteLine(); } if (Program.SteamToken == null) { UpdateSteamToken(); } // If we have not been given any ids then get some from the server if (listOfIds == null) { Console.WriteLine("Getting the steam ids we need to check from the server"); listOfIds = new ListOfId(CustomSocket.StartClient(new StdData("", Program.HostId, 2003).Data)).List; } // Exit if we have no id's if (listOfIds.Count == 0) { Console.WriteLine("No summaries to update"); return(false); } Console.WriteLine("List received of length " + listOfIds.Count); var uri = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=" + Program.SteamToken + "&steamids=" + listOfIds[0]; for (var i = 1; i < listOfIds.Count; i++) { uri += "," + listOfIds[i]; } uri += "&format=xml"; Console.WriteLine("Getting the information from steam"); var people = new List <User>(); try { var s = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore }; var r = XmlReader.Create(uri, s); while (r.Read()) { switch (r.NodeType) { case XmlNodeType.Element: switch (r.Name) { case "player": r.Read(); people.Add(new User()); people[people.Count - 1].LastSummaryUpdate = DateTime.Now; break; case "steamid": r.Read(); people[people.Count - 1].SteamId = UInt64.Parse(r.Value); break; case "communityvisibilitystate": r.Read(); var v = r.Value == "3"; people[people.Count - 1].VisibilityState = v; break; case "personaname": r.Read(); people[people.Count - 1].UserName = r.Value; break; case "lastlogoff": r.Read(); people[people.Count - 1].LastLogOff = new DateTime(1970, 1, 1).AddSeconds(double.Parse(r.Value)); break; case "profileurl": r.Read(); people[people.Count - 1].CustomUrl = r.Value.Split('/')[3] == "id" ? r.Value.Split('/')[4] : "/"; break; case "realname": r.Read(); people[people.Count - 1].RealName = r.Value; break; case "primaryclanid": r.Read(); people[people.Count - 1].PrimaryClanId = UInt64.Parse(r.Value); break; case "timecreated": r.Read(); people[people.Count - 1].MemberSince = new DateTime(1970, 1, 1).AddSeconds(double.Parse(r.Value)); break; case "loccountrycode": r.Read(); people[people.Count - 1].Location = r.Value; break; } break; } } } catch (Exception e) { Console.WriteLine(e); people.RemoveAt(people.Count - 1); } Console.WriteLine("Sending the information back to the server"); CustomSocket.StartClient(new ListOfUsers(people, Program.HostId, 3003).Data); return(true); }
/// <summary> /// Updates the names of games /// </summary> /// <param name="listOfIds">A list of the ids of the game</param> /// <returns>Were there any games that need to be updated</returns> public static bool UpdateGameNames(List <ulong> listOfIds) { if (Program.HostId == 0) { Console.Clear(); UpdateHostId(); Thread.Sleep(1000); Console.Clear(); Console.WriteLine("Server IP: " + Program.IpAddress + " Port: " + Program.Port + " HostId: " + Program.HostId); Console.WriteLine(); } if (Program.SteamToken == null) { UpdateSteamToken(); } // If we have not been given any ids then get some from the server if (listOfIds == null) { Console.WriteLine("Getting the game ids we need to check from the server"); listOfIds = new ListOfId(CustomSocket.StartClient(new StdData("", Program.HostId, 2007).Data)).List; } // Exit if we have no id's if (listOfIds.Count == 0) { Console.WriteLine("No games to update"); return(false); } Console.WriteLine("List received of length " + listOfIds.Count); var list = new List <GameHistory>(); foreach (var listOfId in listOfIds) { var uri = "http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=" + Program.SteamToken + "&steamid=" + listOfId + "&include_played_free_games=1&include_appinfo=1&format=xml"; Console.WriteLine("Getting the information from steam"); try { var s = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore }; var r = XmlReader.Create(uri, s); var temp = new GameHistory(); while (r.Read()) { switch (r.NodeType) { case XmlNodeType.Element: switch (r.Name) { case "appid": r.Read(); temp = new GameHistory(); temp.AppId = Convert.ToInt32(r.Value); break; case "name": r.Read(); temp.Name = r.Value; list.Add(temp); continue; } break; } } list.Add(temp); } catch (Exception e) { Console.WriteLine(e.Message); } } Console.WriteLine("Sending the information back to the server"); CustomSocket.StartClient(new ListOfGames(list, Program.HostId, 3007).Data); return(true); }
/// <summary> /// Updates a list of players friends /// </summary> /// <param name="listOfIds">A list of players, can be null</param> /// <returns>Were there any from the server</returns> public static bool UpdatePlayerFriends(List <ulong> listOfIds) { if (Program.HostId == 0) { Console.Clear(); UpdateHostId(); Thread.Sleep(1000); Console.Clear(); Console.WriteLine("Server IP: " + Program.IpAddress + " Port: " + Program.Port + " HostId: " + Program.HostId); Console.WriteLine(); } if (Program.SteamToken == null) { UpdateSteamToken(); } // If we have not been given any ids then get some from the server if (listOfIds == null) { Console.WriteLine("Getting the steam ids we need to check from the server"); listOfIds = new ListOfId(CustomSocket.StartClient(new StdData("", Program.HostId, 2006).Data)).List; } // Exit if we have no id's if (listOfIds.Count == 0) { Console.WriteLine("No users to update"); return(false); } Console.WriteLine("List received of length " + listOfIds.Count); var list = new List <User>(); foreach (var listOfId in listOfIds) { var uri = "http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=" + Program.SteamToken + "&steamid=" + listOfId + "&relationship=friend&format=xml"; Console.WriteLine("Getting the information from steam"); try { var s = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore }; var r = XmlReader.Create(uri, s); var temp = new User { SteamId = listOfId, LastFriendUpdate = DateTime.Now }; var tempFriend = new Friend(); while (r.Read()) { switch (r.NodeType) { case XmlNodeType.Element: switch (r.Name) { case "steamid": r.Read(); tempFriend = new Friend { SteamId = Convert.ToUInt64(r.Value) }; break; case "friend_since": r.Read(); tempFriend.TimeStamp = new DateTime(1970, 1, 1).AddSeconds(double.Parse(r.Value)); break; } break; case XmlNodeType.EndElement: switch (r.Name) { case "friend": temp.ListOfFriends.Add(tempFriend); break; } break; } } list.Add(temp); } catch (Exception e) { Console.WriteLine(e.Message); } } Console.WriteLine("Sending the information back to the server"); CustomSocket.StartClient(new ListOfUsers(list, Program.HostId, 3006).Data); return(true); }