[DONE] GeoIP Country Login Message
[DONE] GeoIP Country Login Message
Really looking forward to see this /or/ if you can give me a step-by-step guide for 0.535_701.
http://www.mcquai.net/forum/viewtopic.php?f=6&t=28
http://www.mcquai.net/forum/viewtopic.php?f=6&t=28
Last edited by ven000m on September 6th, 2011, 9:56 am, edited 1 time in total.
- boblol0909
- SupOP
- Offline
- Posts: 314
- Joined: June 24th, 2011, 10:27 pm
Re: GeoIP again
His code works, to put it into fcraft make a new class file in the fcraft project called GeoIP.cs and and put in this code:
Then go to Server.cs in the fcraft project and find the method: public static string MakePlayerConnectedMessage( Player player, bool firstTime, World world ).
Replace everything inside the { } with :
That should work, tell me if it doesnt. This will say it when someone connects, i.e. "Boblol0909 connnected again, joined main from: UnitedStates"
Show
Replace everything inside the { } with :
Show
Re: GeoIP again
Well there you go, mod it if you want.
Re: [DONE] GeoIP Country Login Message
anyone skilled to update this for 0.600_dev ? ;P
Re: [DONE] GeoIP Country Login Message
I've done this for 0.6x
Geoip.cs
Replace this section in server.cs (Note I changed login from player.Name to player.ClassyName)
Geoip.cs
Code: Select all
using System;
using System.Net;
using System.Xml;
using System.Data;
namespace fCraft
{
public static class GeoIP
{
public static string GetGeoLocationByIP(string strIPAddress)
{
//Create a WebRequest
WebRequest rssReq = WebRequest.Create("http://freegeoip.appspot.com/xml/" + strIPAddress);
//Create a Proxy
WebProxy px = new WebProxy("http://freegeoip.appspot.com/xml/" + strIPAddress, true);
//Assign the proxy to the WebRequest
rssReq.Proxy = px;
//Set the timeout in Seconds for the WebRequest
rssReq.Timeout = 2000;
try
{
//Get the WebResponse
WebResponse rep = rssReq.GetResponse();
//Read the Response in a XMLTextReader
XmlTextReader xtr = new XmlTextReader(rep.GetResponseStream());
//Create a new DataSet
DataSet ds = new DataSet();
ds.ReadXml(xtr);
DataTable dt = ds.Tables[0];
if (dt != null && dt.Rows.Count > 0)
{
if (dt.Rows[0]["Status"].ToString().Equals("true", StringComparison.CurrentCultureIgnoreCase))
{
if (strIPAddress != "127.0.0.1" && !strIPAddress.StartsWith("192.168."))
return dt.Rows[0]["CountryName"].ToString();
else
return "Au70 Galaxy Headquarters";
}
}
return "";
}
catch
{
return "";
}
}
}
}
Code: Select all
public static string MakePlayerConnectedMessage( Player player, bool firstTime, World world )
{
if( player == null ) throw new ArgumentNullException( "player" );
if( world == null ) throw new ArgumentNullException( "world" );
bool canGetGeo = true;
if (GeoIP.GetGeoLocationByIP(player.IP.ToString()) == "") canGetGeo = false;
string whereFrom = canGetGeo ? "&Sfrom:&c " + GeoIP.GetGeoLocationByIP(player.IP.ToString()) : "";
if( firstTime ) {
return String.Format( "&S{0} ({1}&S) connected, joined {2} {3}",
player.ClassyName,
player.Info.Rank.ClassyName,
world.ClassyName,
whereFrom);
} else {
return String.Format( "&S{0} ({1}&S) connected again, joined {2} {3}",
player.ClassyName,
player.Info.Rank.ClassyName,
world.ClassyName,
whereFrom);
}
}
You cannot use certain BBCodes: [img].
Re: [DONE] GeoIP Country Login Message
Ah and also change the part in geoip for local host.
You cannot use certain BBCodes: [img].
Re: [DONE] GeoIP Country Login Message
I installed the code and it worked perfectly, But i woke up today and checked and it dosnt work anymore, i checked the source for any errors but none, :S
it dosnt show the countrys no more
it dosnt show the countrys no more
-->&<-- Forbidden :O
Re: [DONE] GeoIP Country Login Message
Thats strange. I've never had a problem with it.
Except it says I'm from the United States, but I guess thats an issue with my ISP.
Perhaps you're not running the software with GeoIp in it? Maybe.
Also, Ven000m, the code I posted is for the latest dev version of fCraft. If you're using an earlier dev build, screenshot your coding software and I'll ammend the code for you =)
Except it says I'm from the United States, but I guess thats an issue with my ISP.
Perhaps you're not running the software with GeoIp in it? Maybe.
Also, Ven000m, the code I posted is for the latest dev version of fCraft. If you're using an earlier dev build, screenshot your coding software and I'll ammend the code for you =)
You cannot use certain BBCodes: [img].
Re: [DONE] GeoIP Country Login Message
Its working for me .
Thanks dude!
Thanks dude!