Merge branch 'general-devel' of github.com:TShock/TShock into general-devel-mono

Conflicts:
	TShockAPI/Properties/AssemblyInfo.cs
This commit is contained in:
high 2011-09-03 14:55:21 -04:00
commit 78fa7ab42f
13 changed files with 585 additions and 232 deletions

View file

@ -184,6 +184,7 @@ namespace TShockAPI
add(Permissions.heal, Heal, "heal"); add(Permissions.heal, Heal, "heal");
add(Permissions.buff, Buff, "buff"); add(Permissions.buff, Buff, "buff");
add(Permissions.buffplayer, GBuff, "gbuff", "buffplayer"); add(Permissions.buffplayer, GBuff, "gbuff", "buffplayer");
add(Permissions.grow, Grow, "grow");
} }
public static bool HandleCommand(TSPlayer player, string text) public static bool HandleCommand(TSPlayer player, string text)
@ -2411,11 +2412,11 @@ namespace TShockAPI
{ {
if (args.Parameters.Count < 1 || args.Parameters.Count > 2) if (args.Parameters.Count < 1 || args.Parameters.Count > 2)
{ {
args.Player.SendMessage("Invalid syntax! Proper syntax: /buff <buff id/name> [time(seconds*60)]", Color.Red); args.Player.SendMessage("Invalid syntax! Proper syntax: /buff <buff id/name> [time(seconds)]", Color.Red);
return; return;
} }
int id = 0; int id = 0;
int time = 3600; int time = 60;
if (!int.TryParse(args.Parameters[0], out id)) if (!int.TryParse(args.Parameters[0], out id))
{ {
var found = Tools.GetBuffByName(args.Parameters[0]); var found = Tools.GetBuffByName(args.Parameters[0]);
@ -2430,16 +2431,16 @@ namespace TShockAPI
return; return;
} }
id = found[0]; id = found[0];
}
if (args.Parameters.Count == 2) if (args.Parameters.Count == 2)
int.TryParse(args.Parameters[1], out time); int.TryParse(args.Parameters[1], out time);
}
if (id > 0 && id < Main.maxBuffs) if (id > 0 && id < Main.maxBuffs)
{ {
if (time < 0 || time > short.MaxValue) if (time < 0 || time > short.MaxValue)
time = 3600; time = 60;
args.Player.SetBuff(id, time); args.Player.SetBuff(id, time * 60);
args.Player.SendMessage(string.Format("You have buffed yourself with {0}({1}) for {2} seconds!", args.Player.SendMessage(string.Format("You have buffed yourself with {0}({1}) for {2} seconds!",
Tools.GetBuffName(id), Tools.GetBuffDescription(id), (time / 60)), Color.Green); Tools.GetBuffName(id), Tools.GetBuffDescription(id), (time)), Color.Green);
} }
else else
args.Player.SendMessage("Invalid buff ID!", Color.Red); args.Player.SendMessage("Invalid buff ID!", Color.Red);
@ -2449,11 +2450,11 @@ namespace TShockAPI
{ {
if (args.Parameters.Count < 2 || args.Parameters.Count > 3) if (args.Parameters.Count < 2 || args.Parameters.Count > 3)
{ {
args.Player.SendMessage("Invalid syntax! Proper syntax: /gbuff <player> <buff id/name> [time(seconds*60)]", Color.Red); args.Player.SendMessage("Invalid syntax! Proper syntax: /gbuff <player> <buff id/name> [time(seconds)]", Color.Red);
return; return;
} }
int id = 0; int id = 0;
int time = 3600; int time = 60;
var foundplr = Tools.FindPlayer(args.Parameters[0]); var foundplr = Tools.FindPlayer(args.Parameters[0]);
if (foundplr.Count == 0) if (foundplr.Count == 0)
{ {
@ -2481,23 +2482,89 @@ namespace TShockAPI
return; return;
} }
id = found[0]; id = found[0];
}
if (args.Parameters.Count == 3) if (args.Parameters.Count == 3)
int.TryParse(args.Parameters[2], out time); int.TryParse(args.Parameters[2], out time);
}
if (id > 0 && id < Main.maxBuffs) if (id > 0 && id < Main.maxBuffs)
{ {
if (time < 0 || time > short.MaxValue) if (time < 0 || time > short.MaxValue)
time = 3600; time = 60;
foundplr[0].SetBuff(id, time); foundplr[0].SetBuff(id, time * 60);
args.Player.SendMessage(string.Format("You have buffed {0} with {1}({2}) for {3} seconds!", args.Player.SendMessage(string.Format("You have buffed {0} with {1}({2}) for {3} seconds!",
foundplr[0].Name, Tools.GetBuffName(id), Tools.GetBuffDescription(id), (time / 60)), Color.Green); foundplr[0].Name, Tools.GetBuffName(id), Tools.GetBuffDescription(id), (time)), Color.Green);
foundplr[0].SendMessage(string.Format("{0} has buffed you with {1}({2}) for {3} seconds!", foundplr[0].SendMessage(string.Format("{0} has buffed you with {1}({2}) for {3} seconds!",
args.Player.Name, Tools.GetBuffName(id), Tools.GetBuffDescription(id), (time / 60)), Color.Green); args.Player.Name, Tools.GetBuffName(id), Tools.GetBuffDescription(id), (time)), Color.Green);
} }
else else
args.Player.SendMessage("Invalid buff ID!", Color.Red); args.Player.SendMessage("Invalid buff ID!", Color.Red);
} }
} }
private static void Grow(CommandArgs args)
{
if (args.Parameters.Count != 1)
{
args.Player.SendMessage("Invalid syntax! Proper syntax: /grow [tree/epictree/mushroom/cactus/herb]", Color.Red);
return;
}
var name = "Fail";
var x = args.Player.TileX;
var y = args.Player.TileY + 3;
switch (args.Parameters[0].ToLower())
{
case "tree":
for (int i = x - 1; i < x + 2; i++)
{
Main.tile[i, y].active = true;
Main.tile[i, y].type = 2;
Main.tile[i, y].wall = 0;
}
Main.tile[x, y - 1].wall = 0;
WorldGen.GrowTree(x, y);
name = "Tree";
break;
case "epictree":
for (int i = x - 1; i < x + 2; i++)
{
Main.tile[i, y].active = true;
Main.tile[i, y].type = 2;
Main.tile[i, y].wall = 0;
}
Main.tile[x, y - 1].wall = 0;
Main.tile[x, y - 1].liquid = 0;
Main.tile[x, y - 1].active = true;
WorldGen.GrowEpicTree(x, y);
name = "Epic Tree";
break;
case "mushroom":
for (int i = x - 1; i < x + 2; i++)
{
Main.tile[i, y].active = true;
Main.tile[i, y].type = 70;
Main.tile[i, y].wall = 0;
}
Main.tile[x, y - 1].wall = 0;
WorldGen.GrowShroom(x, y);
name = "Mushroom";
break;
case "cactus":
Main.tile[x, y].type = 53;
WorldGen.GrowCactus(x, y);
name = "Cactus";
break;
case "herb":
Main.tile[x, y].active = true;
Main.tile[x, y].frameX = 36;
Main.tile[x, y].type = 83;
WorldGen.GrowAlch(x, y);
name = "Herb";
break;
default:
args.Player.SendMessage("Unknown plant!", Color.Red);
return;
}
args.Player.SendMessage("You have grown a " + name, Color.Green);
}
#endregion Cheat Comamnds #endregion Cheat Comamnds
} }
} }

View file

@ -184,6 +184,9 @@ namespace TShockAPI
[Description("This is kick players who have custom items in their inventory (via a mod)")] [Description("This is kick players who have custom items in their inventory (via a mod)")]
public bool KickCustomItems = false; public bool KickCustomItems = false;
[Description("This will announce a player's location on join")]
public bool EnableGeoIP = false;
public static ConfigFile Read(string path) public static ConfigFile Read(string path)
{ {
if (!File.Exists(path)) if (!File.Exists(path))

View file

@ -262,7 +262,7 @@ namespace TShockAPI.DB
public bool AddRegion(int tx, int ty, int width, int height, string regionname, string worldid) public bool AddRegion(int tx, int ty, int width, int height, string regionname, string worldid)
{ {
if (TShock.Regions.GetRegionByName(regionname) != null) if (GetRegionByName(regionname) != null)
{ {
return false; return false;
} }
@ -452,6 +452,16 @@ namespace TShockAPI.DB
{ {
return Regions.FirstOrDefault(r => r.Name.Equals(name) && r.WorldID == Main.worldID.ToString()); return Regions.FirstOrDefault(r => r.Name.Equals(name) && r.WorldID == Main.worldID.ToString());
} }
public Region ZacksGetRegionByName(String name)
{
foreach (Region r in Regions)
{
if (r.Name.Equals(name))
return r;
}
return null;
}
} }
public class Region public class Region

259
TShockAPI/GeoIPCountry.cs Normal file
View file

@ -0,0 +1,259 @@
/* GeoIPCountry.cs
*
* Copyright (C) 2008 MaxMind, Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
using System;
using System.IO;
using System.Net;
// This code is based on MaxMind's original C# code, which was ported from Java.
// This version is very simplified and does not support a majority of features for speed.
namespace MaxMind
{
/// <summary>
/// Allows for looking up a country based on an IP address. See www.maxmind.com for more details.
/// </summary>
/// <example>
/// static void Main(string[] args)
/// {
/// using(GeoIPCountry geo = new GeoIPCountry("GeoIP.dat"))
/// {
/// try
/// {
/// Console.WriteLine("Country code of IP address 67.15.94.80: " + geo.GetCountryCode("67.15.94.80"));
/// }
/// catch(Exception ex)
/// {
/// Console.WriteLine(ex.ToString());
/// }
/// }
/// }
/// </example>
public sealed class GeoIPCountry : IDisposable
{
Stream _geodata;
bool _close;
// hard coded position of where country data starts in the data file.
const long COUNTRY_BEGIN = 16776960;
static readonly string[] CountryCodes = {
"--","AP","EU","AD","AE","AF","AG","AI","AL","AM","AN","AO","AQ","AR","AS",
"AT","AU","AW","AZ","BA","BB","BD","BE","BF","BG","BH","BI","BJ","BM","BN",
"BO","BR","BS","BT","BV","BW","BY","BZ","CA","CC","CD","CF","CG","CH","CI",
"CK","CL","CM","CN","CO","CR","CU","CV","CX","CY","CZ","DE","DJ","DK","DM",
"DO","DZ","EC","EE","EG","EH","ER","ES","ET","FI","FJ","FK","FM","FO","FR",
"FX","GA","GB","GD","GE","GF","GH","GI","GL","GM","GN","GP","GQ","GR","GS",
"GT","GU","GW","GY","HK","HM","HN","HR","HT","HU","ID","IE","IL","IN","IO",
"IQ","IR","IS","IT","JM","JO","JP","KE","KG","KH","KI","KM","KN","KP","KR",
"KW","KY","KZ","LA","LB","LC","LI","LK","LR","LS","LT","LU","LV","LY","MA",
"MC","MD","MG","MH","MK","ML","MM","MN","MO","MP","MQ","MR","MS","MT","MU",
"MV","MW","MX","MY","MZ","NA","NC","NE","NF","NG","NI","NL","NO","NP","NR",
"NU","NZ","OM","PA","PE","PF","PG","PH","PK","PL","PM","PN","PR","PS","PT",
"PW","PY","QA","RE","RO","RU","RW","SA","SB","SC","SD","SE","SG","SH","SI",
"SJ","SK","SL","SM","SN","SO","SR","ST","SV","SY","SZ","TC","TD","TF","TG",
"TH","TJ","TK","TM","TN","TO","TL","TR","TT","TV","TW","TZ","UA","UG","UM",
"US","UY","UZ","VA","VC","VE","VG","VI","VN","VU","WF","WS","YE","YT","RS",
"ZA","ZM","ME","ZW","A1","A2","O1","AX","GG","IM","JE","BL","MF"
};
static readonly string[] CountryNames = {
"N/A","Asia/Pacific Region","Europe","Andorra","United Arab Emirates","Afghanistan",
"Antigua and Barbuda","Anguilla","Albania","Armenia","Netherlands Antilles","Angola",
"Antarctica","Argentina","American Samoa","Austria","Australia","Aruba","Azerbaijan",
"Bosnia and Herzegovina","Barbados","Bangladesh","Belgium","Burkina Faso","Bulgaria",
"Bahrain","Burundi","Benin","Bermuda","Brunei Darussalam","Bolivia","Brazil","Bahamas",
"Bhutan","Bouvet Island","Botswana","Belarus","Belize","Canada","Cocos (Keeling) Islands",
"Congo, The Democratic Republic of the","Central African Republic","Congo","Switzerland",
"Cote D'Ivoire","Cook Islands","Chile","Cameroon","China","Colombia","Costa Rica","Cuba",
"Cape Verde","Christmas Island","Cyprus","Czech Republic","Germany","Djibouti","Denmark",
"Dominica","Dominican Republic","Algeria","Ecuador","Estonia","Egypt","Western Sahara",
"Eritrea","Spain","Ethiopia","Finland","Fiji","Falkland Islands (Malvinas)",
"Micronesia, Federated States of","Faroe Islands","France","France, Metropolitan","Gabon",
"United Kingdom","Grenada","Georgia","French Guiana","Ghana","Gibraltar","Greenland",
"Gambia","Guinea","Guadeloupe","Equatorial Guinea","Greece",
"South Georgia and the South Sandwich Islands","Guatemala","Guam","Guinea-Bissau","Guyana",
"Hong Kong","Heard Island and McDonald Islands","Honduras","Croatia","Haiti","Hungary",
"Indonesia","Ireland","Israel","India","British Indian Ocean Territory","Iraq",
"Iran, Islamic Republic of","Iceland","Italy","Jamaica","Jordan","Japan","Kenya",
"Kyrgyzstan","Cambodia","Kiribati","Comoros","Saint Kitts and Nevis",
"Korea, Democratic People's Republic of","Korea, Republic of","Kuwait","Cayman Islands",
"Kazakstan","Lao People's Democratic Republic","Lebanon","Saint Lucia","Liechtenstein",
"Sri Lanka","Liberia","Lesotho","Lithuania","Luxembourg","Latvia","Libyan Arab Jamahiriya",
"Morocco","Monaco","Moldova, Republic of","Madagascar","Marshall Islands","Macedonia",
"Mali","Myanmar","Mongolia","Macau","Northern Mariana Islands","Martinique","Mauritania",
"Montserrat","Malta","Mauritius","Maldives","Malawi","Mexico","Malaysia","Mozambique",
"Namibia","New Caledonia","Niger","Norfolk Island","Nigeria","Nicaragua","Netherlands",
"Norway","Nepal","Nauru","Niue","New Zealand","Oman","Panama","Peru","French Polynesia",
"Papua New Guinea","Philippines","Pakistan","Poland","Saint Pierre and Miquelon",
"Pitcairn Islands","Puerto Rico","Palestinian Territory","Portugal","Palau","Paraguay",
"Qatar","Reunion","Romania","Russian Federation","Rwanda","Saudi Arabia",
"Solomon Islands","Seychelles","Sudan","Sweden","Singapore","Saint Helena","Slovenia",
"Svalbard and Jan Mayen","Slovakia","Sierra Leone","San Marino","Senegal","Somalia",
"Suriname","Sao Tome and Principe","El Salvador","Syrian Arab Republic","Swaziland",
"Turks and Caicos Islands","Chad","French Southern Territories","Togo","Thailand",
"Tajikistan","Tokelau","Turkmenistan","Tunisia","Tonga","Timor-Leste","Turkey",
"Trinidad and Tobago","Tuvalu","Taiwan","Tanzania, United Republic of","Ukraine","Uganda",
"United States Minor Outlying Islands","United States","Uruguay","Uzbekistan",
"Holy See (Vatican City State)","Saint Vincent and the Grenadines","Venezuela",
"Virgin Islands, British","Virgin Islands, U.S.","Vietnam","Vanuatu","Wallis and Futuna",
"Samoa","Yemen","Mayotte","Serbia","South Africa","Zambia","Montenegro","Zimbabwe",
"Anonymous Proxy","Satellite Provider","Other","Aland Islands","Guernsey","Isle of Man",
"Jersey","Saint Barthelemy","Saint Martin"
};
//
// Constructor
//
/// <summary>
/// Initialises a new instance of this class.
/// </summary>
/// <param name="datafile">An already open stream pointing to the contents of a GeoIP.dat file.</param>
/// <remarks>The stream is not closed when this class is disposed. Be sure to clean up afterwards!</remarks>
public GeoIPCountry(Stream datafile)
{
_geodata = datafile;
_close = false;
}
/// <summary>
/// Initialises a new instance of this class, using an on-disk database.
/// </summary>
/// <param name="filename">Path to database file.</param>
/// <remarks>The file will be closed when this class is disposed.</remarks>
public GeoIPCountry(string filename)
{
FileStream fs = new FileStream(filename, FileMode.Open);
_geodata = (Stream)fs;
_close = true;
}
/// <summary>
/// Retrieves a two-letter code, defined by MaxMind, which details the country the specified IP address is located.
/// </summary>
/// <param name="ip">IP address to query.</param>
/// <returns>A two-letter code string. Throws exceptions on failure.</returns>
/// <remarks>The IP address must be IPv4.</remarks>
public string GetCountryCode(IPAddress ip)
{
return CountryCodes[FindIndex(ip)];
}
/// <summary>
/// Retrieves a two-letter code, defined by MaxMind, which details the country the specified IP address is located. Does not throw exceptions on failure.
/// </summary>
/// <param name="ip">IP address to query.</param>
/// <returns>Two-letter country code or null on failure.</returns>
public string TryGetCountryCode(IPAddress ip)
{
try
{
return CountryCodes[FindIndex(ip)];
}
catch (Exception)
{
return null;
}
}
/// <summary>
/// Gets the English name of a country, by a country code.
/// </summary>
/// <param name="countrycode">Country code to look up, returned by GetCountryCode or TryGetCountryCode.</param>
/// <returns>English name of the country, or null on failure.</returns>
public static string GetCountryNameByCode(string countrycode)
{
int index = Array.IndexOf(CountryCodes, countrycode);
return index == -1 ? null : CountryNames[index];
}
int FindIndex(IPAddress ip)
{
return (int)FindCountryCode(0, AddressToLong(ip), 31);
}
// Converts an IPv4 address into a long, for reading from geo database
long AddressToLong(IPAddress ip)
{
if (ip.AddressFamily != System.Net.Sockets.AddressFamily.InterNetwork)
throw new InvalidOperationException("IP address is not IPv4");
long num = 0;
byte[] bytes = ip.GetAddressBytes();
for (int i = 0; i < 4; ++i)
{
long y = bytes[i];
if (y < 0)
y += 256;
num += y << ((3 - i) * 8);
}
return num;
}
// Traverses the GeoIP binary data looking for a country code based
// on the IP address mask
long FindCountryCode(long offset, long ipnum, int depth)
{
byte[] buffer = new byte[6]; // 2 * MAX_RECORD_LENGTH
long[] x = new long[2];
if (depth < 0)
throw new IOException("Cannot seek GeoIP database");
_geodata.Seek(6 * offset, SeekOrigin.Begin);
_geodata.Read(buffer, 0, 6);
for (int i = 0; i < 2; i++)
{
x[i] = 0;
for (int j = 0; j < 3; j++)
{
int y = buffer[i * 3 + j];
if (y < 0)
y += 256;
x[i] += (y << (j * 8));
}
}
if ((ipnum & (1 << depth)) > 0)
{
if (x[1] >= COUNTRY_BEGIN)
return x[1] - COUNTRY_BEGIN;
return FindCountryCode(x[1], ipnum, depth - 1);
}
else
{
if (x[0] >= COUNTRY_BEGIN)
return x[0] - COUNTRY_BEGIN;
return FindCountryCode(x[0], ipnum, depth - 1);
}
}
public void Dispose()
{
if (_close && _geodata != null)
{
_geodata.Close();
_geodata = null;
}
}
}
}

View file

@ -213,7 +213,7 @@ namespace TShockAPI
Tools.ForceKick(args.Player, "Server is set to hardcore characters only!"); Tools.ForceKick(args.Player, "Server is set to hardcore characters only!");
return true; return true;
} }
args.Player.Difficulty = difficulty;
args.Player.ReceivedInfo = true; args.Player.ReceivedInfo = true;
return false; return false;
} }
@ -480,7 +480,7 @@ namespace TShockAPI
return true; return true;
} }
if (type == 23 && float.IsNaN((float)Math.Sqrt((double)(velx * velx + vely * vely)))) if (type == 23 && (vely == 0f || velx == 0f)) //float.IsNaN((float)Math.Sqrt((double)(velx * velx + vely * vely))))
{ {
Tools.HandleGriefer(args.Player, TShock.Config.ProjectileAbuseReason); Tools.HandleGriefer(args.Player, TShock.Config.ProjectileAbuseReason);
return true; return true;
@ -511,6 +511,7 @@ namespace TShockAPI
return Tools.HandleGriefer(args.Player, TShock.Config.KillMeAbuseReason); return Tools.HandleGriefer(args.Player, TShock.Config.KillMeAbuseReason);
} }
args.Player.LastDeath = DateTime.Now; args.Player.LastDeath = DateTime.Now;
if (args.Player.Difficulty != 2)
args.Player.ForceSpawn = true; args.Player.ForceSpawn = true;
return false; return false;
} }

View file

@ -132,6 +132,9 @@ namespace TShockAPI
[Description("User can buff other players")] [Description("User can buff other players")]
public static readonly string buffplayer; public static readonly string buffplayer;
[Description("")]
public static readonly string grow;
static Permissions() static Permissions()
{ {
foreach (var field in typeof(Permissions).GetFields()) foreach (var field in typeof(Permissions).GetFields())

View file

@ -36,5 +36,5 @@ using System.Runtime.InteropServices;
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.2.8.0903")] [assembly: AssemblyVersion("3.3.0.0903")]
[assembly: AssemblyFileVersion("3.2.8.0903")] [assembly: AssemblyFileVersion("3.3.0.0903")]

View file

@ -60,6 +60,8 @@ namespace TShockAPI
public bool RequestedSection = false; public bool RequestedSection = false;
public DateTime LastDeath { get; set; } public DateTime LastDeath { get; set; }
public bool ForceSpawn = false; public bool ForceSpawn = false;
public string Country = "??";
public int Difficulty;
public bool RealPlayer public bool RealPlayer
{ {

View file

@ -18,10 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* TShock wouldn't be possible without: /* TShock wouldn't be possible without:
* Github * Github
* Microsoft Visual Studio 2010 * Microsoft Visual Studio 2010
* HostPenda * Adrenic
* And you, for your continued support and devotion to the evolution of TShock * And you, for your continued support and devotion to the evolution of TShock
* Kerplunc Gaming * Kerplunc Gaming
* TerrariaGSP * TerrariaGSP
* XNS Technology Group (Xenon Servers)
*/ */
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -48,7 +49,7 @@ namespace TShockAPI
public class TShock : TerrariaPlugin public class TShock : TerrariaPlugin
{ {
public static readonly Version VersionNum = Assembly.GetExecutingAssembly().GetName().Version; public static readonly Version VersionNum = Assembly.GetExecutingAssembly().GetName().Version;
public static readonly string VersionCodename = "Yes, we're adding Logblock style functionality soon, don't worry."; public static readonly string VersionCodename = "And believe me, we are still alive.";
public static string SavePath = "tshock"; public static string SavePath = "tshock";
@ -65,6 +66,7 @@ namespace TShockAPI
public static IDbConnection DB; public static IDbConnection DB;
public static bool OverridePort; public static bool OverridePort;
public static PacketBufferer PacketBuffer; public static PacketBufferer PacketBuffer;
public static MaxMind.GeoIPCountry Geo;
/// <summary> /// <summary>
/// Called after TShock is initialized. Useful for plugins that needs hooks before tshock but also depend on tshock being loaded. /// Called after TShock is initialized. Useful for plugins that needs hooks before tshock but also depend on tshock being loaded.
@ -170,6 +172,8 @@ namespace TShockAPI
Regions = new RegionManager(DB); Regions = new RegionManager(DB);
Itembans = new ItemManager(DB); Itembans = new ItemManager(DB);
RememberedPos = new RemeberedPosManager(DB); RememberedPos = new RemeberedPosManager(DB);
if (Config.EnableGeoIP)
Geo = new MaxMind.GeoIPCountry(Path.Combine(SavePath, "GeoIP.dat"));
Log.ConsoleInfo(string.Format("TShock Version {0} ({1}) now running.", Version, VersionCodename)); Log.ConsoleInfo(string.Format("TShock Version {0} ({1}) now running.", Version, VersionCodename));
@ -620,6 +624,14 @@ namespace TShockAPI
NetMessage.SendData((int)PacketTypes.TimeSet, -1, -1, "", 0, 0, Main.sunModY, Main.moonModY); NetMessage.SendData((int)PacketTypes.TimeSet, -1, -1, "", 0, 0, Main.sunModY, Main.moonModY);
NetMessage.syncPlayers(); NetMessage.syncPlayers();
if (Config.EnableGeoIP)
{
var code = Geo.TryGetCountryCode(IPAddress.Parse(player.IP));
player.Country = code == null ? "N/A" : MaxMind.GeoIPCountry.GetCountryNameByCode(code);
Log.Info(string.Format("{0} ({1}) from '{2}' group from '{3}' joined.", player.Name, player.IP, player.Group.Name, player.Country));
Tools.Broadcast(player.Name + " is from the " + player.Country, Color.Yellow);
}
else
Log.Info(string.Format("{0} ({1}) from '{2}' group joined.", player.Name, player.IP, player.Group.Name)); Log.Info(string.Format("{0} ({1}) from '{2}' group joined.", player.Name, player.IP, player.Group.Name));
Tools.ShowFileToUser(player, "motd.txt"); Tools.ShowFileToUser(player, "motd.txt");

View file

@ -97,6 +97,7 @@
<Compile Include="DB\UserManager.cs" /> <Compile Include="DB\UserManager.cs" />
<Compile Include="Extensions\RandomExt.cs" /> <Compile Include="Extensions\RandomExt.cs" />
<Compile Include="Extensions\StringExt.cs" /> <Compile Include="Extensions\StringExt.cs" />
<Compile Include="GeoIPCountry.cs" />
<Compile Include="IPackable.cs" /> <Compile Include="IPackable.cs" />
<Compile Include="Commands.cs" /> <Compile Include="Commands.cs" />
<Compile Include="ConfigFile.cs" /> <Compile Include="ConfigFile.cs" />
@ -176,7 +177,7 @@
</PropertyGroup> </PropertyGroup>
<ProjectExtensions> <ProjectExtensions>
<VisualStudio> <VisualStudio>
<UserProperties BuildVersion_UpdateAssemblyVersion="True" BuildVersion_UpdateFileVersion="True" BuildVersion_BuildAction="Both" BuildVersion_BuildVersioningStyle="None.None.None.MonthAndDayStamp" BuildVersion_StartDate="2011/6/17" BuildVersion_IncrementBeforeBuild="False" /> <UserProperties BuildVersion_IncrementBeforeBuild="False" BuildVersion_StartDate="2011/6/17" BuildVersion_BuildVersioningStyle="None.None.None.MonthAndDayStamp" BuildVersion_BuildAction="Both" BuildVersion_UpdateFileVersion="True" BuildVersion_UpdateAssemblyVersion="True" />
</VisualStudio> </VisualStudio>
</ProjectExtensions> </ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Drawing;
using System.Text; using System.Text;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -7,7 +8,7 @@ using System.Data;
using TShockAPI; using TShockAPI;
using Community.CsharpSqlite.SQLiteClient; using Community.CsharpSqlite.SQLiteClient;
using TShockAPI.DB; using TShockAPI.DB;
using Microsoft.Xna.Framework; using Region = TShockAPI.DB.Region;
namespace UnitTests namespace UnitTests
{ {
@ -29,6 +30,7 @@ namespace UnitTests
DB.Open(); DB.Open();
manager = new RegionManager(DB); manager = new RegionManager(DB);
TShock.Regions = manager;
manager.ReloadForUnitTest("test"); manager.ReloadForUnitTest("test");
} }
@ -39,12 +41,12 @@ namespace UnitTests
Region r = new Region( new Rectangle(100,100,100,100), "test", true, "test"); Region r = new Region( new Rectangle(100,100,100,100), "test", true, "test");
Assert.IsTrue(manager.AddRegion(r.Area.X, r.Area.Y, r.Area.Width, r.Area.Height, r.Name, r.WorldID)); Assert.IsTrue(manager.AddRegion(r.Area.X, r.Area.Y, r.Area.Width, r.Area.Height, r.Name, r.WorldID));
Assert.AreEqual(1, manager.Regions.Count); Assert.AreEqual(1, manager.Regions.Count);
Assert.IsNotNull(manager.getRegion("test")); Assert.IsNotNull(manager.ZacksGetRegionByName("test"));
Region r2 = new Region(new Rectangle(201, 201, 100, 100), "test2", true, "test"); Region r2 = new Region(new Rectangle(201, 201, 100, 100), "test2", true, "test");
manager.AddRegion(r2.Area.X, r2.Area.Y, r2.Area.Width, r2.Area.Height, r2.Name, r2.WorldID); manager.AddRegion(r2.Area.X, r2.Area.Y, r2.Area.Width, r2.Area.Height, r2.Name, r2.WorldID);
Assert.AreEqual(2, manager.Regions.Count); Assert.AreEqual(2, manager.Regions.Count);
Assert.IsNotNull(manager.getRegion("test2")); Assert.IsNotNull(manager.ZacksGetRegionByName("test2"));
} }
[TestMethod] [TestMethod]
@ -73,16 +75,16 @@ namespace UnitTests
[TestMethod] [TestMethod]
public void SetRegionState() public void SetRegionState()
{ {
Assert.IsTrue(manager.getRegion("test").DisableBuild); Assert.IsTrue(manager.ZacksGetRegionByName("test").DisableBuild);
manager.SetRegionStateTest("test", "test", false); manager.SetRegionStateTest("test", "test", false);
Assert.IsTrue(!manager.getRegion("test").DisableBuild); Assert.IsTrue(!manager.ZacksGetRegionByName("test").DisableBuild);
manager.SetRegionStateTest("test", "test", true); manager.SetRegionStateTest("test", "test", true);
Assert.IsTrue(manager.getRegion("test").DisableBuild); Assert.IsTrue(manager.ZacksGetRegionByName("test").DisableBuild);
Assert.IsTrue(manager.getRegion("test2").DisableBuild); Assert.IsTrue(manager.ZacksGetRegionByName("test2").DisableBuild);
manager.SetRegionStateTest("test2", "test", false); manager.SetRegionStateTest("test2", "test", false);
Assert.IsTrue(!manager.getRegion("test2").DisableBuild); Assert.IsTrue(!manager.ZacksGetRegionByName("test2").DisableBuild);
manager.SetRegionStateTest("test2", "test", true); manager.SetRegionStateTest("test2", "test", true);
Assert.IsTrue(manager.getRegion("test2").DisableBuild); Assert.IsTrue(manager.ZacksGetRegionByName("test2").DisableBuild);
} }
[TestMethod] [TestMethod]

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<OrderedTest name="regionmanagertest" storage="c:\users\virus\git\tshock\unittests\regionmanagertest.orderedtest" id="7601a790-d2fb-45d2-a612-1ae4de84eb61" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010"> <OrderedTest name="regionmanagertest" storage="c:\users\shank\dropbox\design and development\csharp\tshock\unittests\regionmanagertest.orderedtest" id="7601a790-d2fb-45d2-a612-1ae4de84eb61" continueAfterFailure="true" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Execution id="e2bb6bb7-7bc7-43d5-bb81-e2d13d377599" /> <Execution id="41a9a1cc-4b4c-466c-b54a-8bd056d3489f" />
<TestLinks> <TestLinks>
<TestLink id="8d92e80b-8c9d-7a14-5c3a-eba6790be784" name="AddRegion" storage="bin\release\unittests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> <TestLink id="8d92e80b-8c9d-7a14-5c3a-eba6790be784" name="AddRegion" storage="bin\release\unittests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<TestLink id="57686a56-2684-8c17-1564-ed9a3c37b167" name="InRegion" storage="bin\release\unittests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> <TestLink id="57686a56-2684-8c17-1564-ed9a3c37b167" name="InRegion" storage="bin\release\unittests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

View file

@ -14,6 +14,7 @@
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl> <PublishUrl>publish\</PublishUrl>
<Install>true</Install> <Install>true</Install>
<InstallFrom>Disk</InstallFrom> <InstallFrom>Disk</InstallFrom>
@ -26,7 +27,6 @@
<MapFileExtensions>true</MapFileExtensions> <MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision> <ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion> <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust> <UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled> <BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup> </PropertyGroup>
@ -55,10 +55,6 @@
<HintPath>..\SqlBins\Community.CsharpSqlite.SQLiteClient.dll</HintPath> <HintPath>..\SqlBins\Community.CsharpSqlite.SQLiteClient.dll</HintPath>
</Reference> </Reference>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Microsoft.Xna.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\Windows\Microsoft.NET\assembly\GAC_32\Microsoft.Xna.Framework\v4.0_4.0.0.0__842cf8be1de50553\Microsoft.Xna.Framework.dll</HintPath>
</Reference>
<Reference Include="MySql.Data"> <Reference Include="MySql.Data">
<HintPath>..\SqlBins\MySql.Data.dll</HintPath> <HintPath>..\SqlBins\MySql.Data.dll</HintPath>
</Reference> </Reference>
@ -71,14 +67,11 @@
</Reference> </Reference>
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Drawing" />
<Reference Include="TerrariaServerAPI, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="TerrariaServerAPI, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\TerrariaServerBins\TerrariaServerAPI.dll</HintPath> <HintPath>..\TerrariaServerBins\TerrariaServerAPI.dll</HintPath>
</Reference> </Reference>
<Reference Include="XNAHelpers, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\TerrariaServerBins\XNAHelpers.dll</HintPath>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">