Remove a bunch of obsolete methods

This commit is contained in:
UnknownShadow200 2017-09-22 10:43:09 +10:00
parent 774040e9d7
commit 46c571e7f0
9 changed files with 49 additions and 91 deletions

View File

@ -16,6 +16,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using MCGalaxy.Network;
using MCGalaxy.Util;
namespace MCGalaxy {
@ -95,7 +96,7 @@ namespace MCGalaxy {
static string TokenDate(Player p) { return DateTime.Now.ToString("yyyy-MM-dd"); }
static string TokenTime(Player p) { return DateTime.Now.ToString("HH:mm:ss"); }
static string TokenIP(Player p) { return p.ip; }
static string TokenServerIP(Player p) { return Player.IsLocalIpAddress(p.ip) ? p.ip : Server.IP; }
static string TokenServerIP(Player p) { return HttpUtil.IsLocalIP(p.ip) ? p.ip : Server.IP; }
static string TokenColor(Player p) { return p.color; }
static string TokenRank(Player p) { return p.group.Name; }
static string TokenLevel(Player p) { return p.level == null ? null : p.level.name; }

View File

@ -41,7 +41,7 @@ namespace MCGalaxy.Commands.Moderation {
target = match.name; ip = match.ip;
}
if (Player.IPInPrivateRange(ip)) {
if (HttpUtil.IsPrivateIP(ip)) {
Player.Message(p, Colors.red + "Player has an internal IP, cannot trace"); return;
}

View File

@ -15,6 +15,7 @@ permissions and limitations under the Licenses.
using System;
using System.Security.Cryptography;
using MCGalaxy.Events;
using MCGalaxy.Network;
namespace MCGalaxy.Core {
internal static class ConnectingHandler {
@ -82,7 +83,7 @@ namespace MCGalaxy.Core {
string hashHex = BitConverter.ToString(hash);
if (!mppass.CaselessEq(hashHex.Replace("-", ""))) {
if (!Player.IPInPrivateRange(p.ip)) {
if (!HttpUtil.IsPrivateIP(p.ip)) {
p.Leave(null, "Login failed! Close the game and sign in again.", true); return false;
}
} else {
@ -126,7 +127,7 @@ namespace MCGalaxy.Core {
if (Server.vip.Contains(p.name)) return true;
Player[] online = PlayerInfo.Online.Items;
if (online.Length >= ServerConfig.MaxPlayers && !Player.IPInPrivateRange(p.ip)) {
if (online.Length >= ServerConfig.MaxPlayers && !HttpUtil.IsPrivateIP(p.ip)) {
p.Leave(null, "Server full!", true); return false;
}
if (group.Permission > LevelPermission.Guest) return true;

View File

@ -17,6 +17,7 @@
*/
using System;
using System.Collections.Generic;
using MCGalaxy.Network;
using MCGalaxy.Tasks;
namespace MCGalaxy.Core {
@ -27,7 +28,7 @@ namespace MCGalaxy.Core {
static readonly object ipsLock = new object();
internal static bool CheckIP(Player p) {
if (!ServerConfig.IPSpamCheck || Player.IsLocalIpAddress(p.ip)) return true;
if (!ServerConfig.IPSpamCheck || HttpUtil.IsLocalIP(p.ip)) return true;
DateTime blockedUntil, now = DateTime.UtcNow;
lock (ipsLock) {

View File

@ -211,12 +211,6 @@ namespace MCGalaxy {
return x >= 0 && y >= 0 && z >= 0 && x < Width && y < Height && z < Length;
}
[Obsolete]
public static Level Find(string name) { return LevelInfo.Find(name); }
[Obsolete]
public static Level FindExact(string name) { return LevelInfo.FindExact(name); }
public static void SaveSettings(Level lvl) {
if (lvl.IsMuseum) return; // museums do not save properties

View File

@ -26,20 +26,6 @@ namespace MCGalaxy {
/// <summary> Array of all current loaded levels. </summary>
/// <remarks> Note this field is highly volatile, you should cache references to the items array. </remarks>
public static VolatileArray<Level> Loaded = new VolatileArray<Level>(true);
[Obsolete("Prefer Matcher.FindLevels() or FindExact()")]
public static Level Find(string name) {
Level match = null; int matches = 0;
Level[] loaded = Loaded.Items;
foreach (Level lvl in loaded) {
if (lvl.name.CaselessEq(name)) return lvl;
if (lvl.name.CaselessContains(name)) {
match = lvl; matches++;
}
}
return matches == 1 ? match : null;
}
public static Level FindExact(string name) {
Level[] loaded = Loaded.Items;

View File

@ -1,20 +1,17 @@
/*
Copyright 2015 MCGalaxy
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.
*/
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy)
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 System.Net;
@ -53,5 +50,33 @@ namespace MCGalaxy.Network {
if (remoteEndPoint.AddressFamily != localIP.AddressFamily) return null;
return new IPEndPoint(localIP, 0);
}
public static bool IsPrivateIP(string ip) {
//range of 172.16.0.0 - 172.31.255.255
if (ip.StartsWith("172.") && (int.Parse(ip.Split('.')[1]) >= 16 && int.Parse(ip.Split('.')[1]) <= 31))
return true;
return IPAddress.IsLoopback(IPAddress.Parse(ip)) || ip.StartsWith("192.168.") || ip.StartsWith("10.");
//return IsLocalIpAddress(ip);
}
public static bool IsLocalIP(string ip) {
try { // get host IP addresses
IPAddress[] hostIPs = Dns.GetHostAddresses(ip);
// get local IP addresses
IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
// test if any host IP equals to any local IP or to localhost
foreach ( IPAddress hostIP in hostIPs ) {
// is localhost
if ( IPAddress.IsLoopback(hostIP) ) return true;
// is local address
foreach ( IPAddress localIP in localIPs ) {
if ( hostIP.Equals(localIP) ) return true;
}
}
}
catch { }
return false;
}
}
}

View File

@ -349,12 +349,6 @@ namespace MCGalaxy {
[Obsolete("Use PlayerInfo.Online.Items")]
public static List<Player> players;
[Obsolete("Use PlayerInfo.Find(name)")]
public static Player Find(string name) { return PlayerInfo.Find(name); }
[Obsolete("Use PlayerInfo.FindExact(name)")]
public static Player FindExact(string name) { return PlayerInfo.FindExact(name); }
public static bool ValidName(string name) {
const string valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890._+";
@ -377,34 +371,6 @@ namespace MCGalaxy {
public void RevertBlock(ushort x, ushort y, ushort z) {
SendBlockchange(x, y, z, level.GetBlock(x, y, z));
}
public static bool IPInPrivateRange(string ip) {
//range of 172.16.0.0 - 172.31.255.255
if (ip.StartsWith("172.") && (int.Parse(ip.Split('.')[1]) >= 16 && int.Parse(ip.Split('.')[1]) <= 31))
return true;
return IPAddress.IsLoopback(IPAddress.Parse(ip)) || ip.StartsWith("192.168.") || ip.StartsWith("10.");
//return IsLocalIpAddress(ip);
}
public static bool IsLocalIpAddress(string host) {
try { // get host IP addresses
IPAddress[] hostIPs = Dns.GetHostAddresses(host);
// get local IP addresses
IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
// test if any host IP equals to any local IP or to localhost
foreach ( IPAddress hostIP in hostIPs ) {
// is localhost
if ( IPAddress.IsLoopback(hostIP) ) return true;
// is local address
foreach ( IPAddress localIP in localIPs ) {
if ( hostIP.Equals(localIP) ) return true;
}
}
}
catch { }
return false;
}
public void SetMoney(int amount) {
money = amount;

View File

@ -43,22 +43,6 @@ namespace MCGalaxy {
return count;
}
[Obsolete("Prefer FindMatches() or FindExact()")]
public static Player Find(string name) {
Player[] players = PlayerInfo.Online.Items;
Player match = null; int matches = 0;
name = name.ToLower();
foreach (Player p in players) {
if (p.name.CaselessEq(name)) return p;
if (p.name.CaselessContains(name)) {
match = p; matches++;
}
}
return matches == 1 ? match : null;
}
public static Player FindMatches(Player pl, string name, bool onlyCanSee = true) {
int matches = 0; return FindMatches(pl, name, out matches, onlyCanSee);
}