mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-10-01 17:45:57 -04:00
Cleanup /location, also move input handling code into a separate file.
This commit is contained in:
parent
1f86415dfc
commit
8caf30d81b
@ -16,55 +16,66 @@
|
|||||||
permissions and limitations under the Licenses.
|
permissions and limitations under the Licenses.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using MCGalaxy.SQL;
|
|
||||||
using System.Data;
|
using System.Data;
|
||||||
namespace MCGalaxy.Commands
|
using System.IO;
|
||||||
{
|
using System.Net;
|
||||||
public class CmdLocation : Command
|
using MCGalaxy.SQL;
|
||||||
{
|
|
||||||
|
namespace MCGalaxy.Commands {
|
||||||
|
|
||||||
|
public class CmdLocation : Command {
|
||||||
|
|
||||||
public override string name { get { return "location"; } }
|
public override string name { get { return "location"; } }
|
||||||
public override string shortcut { get { return "lo"; } }
|
public override string shortcut { get { return "lo"; } }
|
||||||
public override string type { get { return CommandTypes.Moderation; } }
|
public override string type { get { return CommandTypes.Moderation; } }
|
||||||
public override bool museumUsable { get { return true; } }
|
public override bool museumUsable { get { return true; } }
|
||||||
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
|
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
|
||||||
public CmdLocation() { }
|
public CmdLocation() { }
|
||||||
public override void Use(Player p, string message)
|
|
||||||
{
|
public override void Use(Player p, string message) {
|
||||||
Player who = null;
|
string ip = "";
|
||||||
string searchip = "";
|
Player who = PlayerInfo.Find(message);
|
||||||
string name;
|
if (who == null) {
|
||||||
who = PlayerInfo.Find(message);
|
Player.SendMessage(p, "&eNo online player \"" + message + "\", searching database..");
|
||||||
if (who == null)
|
|
||||||
{
|
|
||||||
Player.SendMessage(p, Colors.red + "Could not find player " + message + " ...searching in database");
|
|
||||||
Database.AddParams("@Name", message);
|
Database.AddParams("@Name", message);
|
||||||
DataTable playerDb = Database.fillData("SELECT * FROM Players WHERE Name=@Name");
|
DataTable playerDb = Database.fillData("SELECT * FROM Players WHERE Name=@Name");
|
||||||
if (playerDb.Rows.Count == 0)
|
if (playerDb.Rows.Count == 0) {
|
||||||
{
|
Player.SendMessage(p, "&cCould not find player at all"); return;
|
||||||
Player.SendMessage(p, Colors.red + "Could not find player at all");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else
|
ip = (string)playerDb.Rows[0]["IP"];
|
||||||
searchip = (string)playerDb.Rows[0]["IP"];
|
} else {
|
||||||
|
ip = who.ip;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
searchip = who.ip;
|
|
||||||
if (Player.IPInPrivateRange(searchip))
|
|
||||||
{
|
|
||||||
Player.SendMessage(p, Colors.red + "Player has an internal IP, cannot trace");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (who != null)
|
|
||||||
name = who.name;
|
|
||||||
else
|
|
||||||
name = message;
|
|
||||||
|
|
||||||
Player.SendMessage(p, Colors.lime + "The IP of " + Colors.aqua + name + Colors.lime + " has been traced to: " + Colors.aqua + Player.GetIPLocation(searchip));
|
if (Player.IPInPrivateRange(ip)) {
|
||||||
|
Player.SendMessage(p, Colors.red + "Player has an internal IP, cannot trace"); return;
|
||||||
}
|
}
|
||||||
public override void Help(Player p)
|
string name = who != null ? who.name : message;
|
||||||
|
Player.SendMessage(p, "&aThe IP of &b" + name + " &ahas been traced to: &b" + GetIPLocation(ip));
|
||||||
|
}
|
||||||
|
|
||||||
|
static string GetIPLocation(string IP) {
|
||||||
|
string city, country;
|
||||||
|
WebRequest reqCity = WebRequest.Create("http://ipinfo.io/" + IP + "/city");
|
||||||
|
WebRequest reqCountry = WebRequest.Create("http://ipinfo.io/" + IP + "/country");
|
||||||
|
using (WebResponse resp = reqCity.GetResponse())
|
||||||
|
using (StreamReader reader = new StreamReader(resp.GetResponseStream()))
|
||||||
{
|
{
|
||||||
|
city = reader.ReadToEnd().Replace("\n", "");
|
||||||
|
if (city == "")
|
||||||
|
city = "Unknown";
|
||||||
|
}
|
||||||
|
|
||||||
|
using (WebResponse resp = reqCountry.GetResponse())
|
||||||
|
using (StreamReader reader = new StreamReader(resp.GetResponseStream()))
|
||||||
|
{
|
||||||
|
country = reader.ReadToEnd().Replace("\n", "");
|
||||||
|
}
|
||||||
|
return city + "/" + country;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Help(Player p) {
|
||||||
Player.SendMessage(p, "/location <name> - Tracks down the location of the IP associated with <name>.");
|
Player.SendMessage(p, "/location <name> - Tracks down the location of the IP associated with <name>.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -437,6 +437,7 @@
|
|||||||
<Compile Include="Player\Group\Group.cs" />
|
<Compile Include="Player\Group\Group.cs" />
|
||||||
<Compile Include="Player\Group\GroupCommands.cs" />
|
<Compile Include="Player\Group\GroupCommands.cs" />
|
||||||
<Compile Include="Player\Group\GroupProperties.cs" />
|
<Compile Include="Player\Group\GroupProperties.cs" />
|
||||||
|
<Compile Include="Player\Player.Handlers.cs" />
|
||||||
<Compile Include="Player\PlayerInfo.cs" />
|
<Compile Include="Player\PlayerInfo.cs" />
|
||||||
<Compile Include="Player\Waypoint.cs" />
|
<Compile Include="Player\Waypoint.cs" />
|
||||||
<Compile Include="Player\Player.Timers.cs" />
|
<Compile Include="Player\Player.Timers.cs" />
|
||||||
|
1667
Player/Player.Handlers.cs
Normal file
1667
Player/Player.Handlers.cs
Normal file
File diff suppressed because it is too large
Load Diff
1693
Player/Player.cs
1693
Player/Player.cs
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user