Cleanup /location, also move input handling code into a separate file.

This commit is contained in:
UnknownShadow200 2016-02-15 11:46:53 +11:00
parent 1f86415dfc
commit 8caf30d81b
4 changed files with 1753 additions and 1747 deletions

View File

@ -1,70 +1,81 @@
/*
Copyright 2015 MCGalaxy team
Copyright 2015 MCGalaxy team
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using System;
using MCGalaxy.SQL;
using System.Data;
namespace MCGalaxy.Commands
{
public class CmdLocation : Command
{
using System.IO;
using System.Net;
using MCGalaxy.SQL;
namespace MCGalaxy.Commands {
public class CmdLocation : Command {
public override string name { get { return "location"; } }
public override string shortcut { get { return "lo"; } }
public override string type { get { return CommandTypes.Moderation; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
public CmdLocation() { }
public override void Use(Player p, string message)
{
Player who = null;
string searchip = "";
string name;
who = PlayerInfo.Find(message);
if (who == null)
{
Player.SendMessage(p, Colors.red + "Could not find player " + message + " ...searching in database");
public override void Use(Player p, string message) {
string ip = "";
Player who = PlayerInfo.Find(message);
if (who == null) {
Player.SendMessage(p, "&eNo online player \"" + message + "\", searching database..");
Database.AddParams("@Name", message);
DataTable playerDb = Database.fillData("SELECT * FROM Players WHERE Name=@Name");
if (playerDb.Rows.Count == 0)
{
Player.SendMessage(p, Colors.red + "Could not find player at all");
return;
if (playerDb.Rows.Count == 0) {
Player.SendMessage(p, "&cCould not find player at all"); return;
}
else
searchip = (string)playerDb.Rows[0]["IP"];
ip = (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;
}
string name = who != null ? who.name : message;
Player.SendMessage(p, "&aThe IP of &b" + name + " &ahas been traced to: &b" + GetIPLocation(ip));
}
public override void Help(Player p)
{
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>.");
}
}
}

View File

@ -437,6 +437,7 @@
<Compile Include="Player\Group\Group.cs" />
<Compile Include="Player\Group\GroupCommands.cs" />
<Compile Include="Player\Group\GroupProperties.cs" />
<Compile Include="Player\Player.Handlers.cs" />
<Compile Include="Player\PlayerInfo.cs" />
<Compile Include="Player\Waypoint.cs" />
<Compile Include="Player\Player.Timers.cs" />

1667
Player/Player.Handlers.cs Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff