[DONE] GeoIP Country Login Message

Fixed bugs, solved problems, and old reports.
Locked
ven000m
Offline
Posts: 31
Joined: May 25th, 2011, 1:14 am

[DONE] GeoIP Country Login Message

Post by ven000m »

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
Last edited by ven000m on September 6th, 2011, 9:56 am, edited 1 time in total.

User avatar
boblol0909
SupOP
Offline
Posts: 314
Joined: June 24th, 2011, 10:27 pm

Re: GeoIP again

Post by boblol0909 »

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:
Show
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 :
Show
That should work, tell me if it doesnt. This will say it when someone connects, i.e. "Boblol0909 connnected again, joined main from: UnitedStates"

User avatar
fragmer
fCraft Developer
Offline
Posts: 1386
Joined: May 21st, 2011, 10:53 pm

Re: GeoIP again

Post by fragmer »

Well there you go, mod it if you want.

ven000m
Offline
Posts: 31
Joined: May 25th, 2011, 1:14 am

Re: GeoIP again

Post by ven000m »

WORKED!

ven000m
Offline
Posts: 31
Joined: May 25th, 2011, 1:14 am

Re: [DONE] GeoIP Country Login Message

Post by ven000m »

anyone skilled to update this for 0.600_dev ? ;P

Jonty800
Offline
Posts: 280
Joined: August 21st, 2011, 6:31 am
Location: United Kingdom
Contact:

Re: [DONE] GeoIP Country Login Message

Post by Jonty800 »

I've done this for 0.6x


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 "";
            }
        }
    }
}
Replace this section in server.cs (Note I changed login from player.Name to player.ClassyName)

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].

Jonty800
Offline
Posts: 280
Joined: August 21st, 2011, 6:31 am
Location: United Kingdom
Contact:

Re: [DONE] GeoIP Country Login Message

Post by Jonty800 »

Ah and also change the part in geoip for local host.
You cannot use certain BBCodes: [img].

User avatar
Kitteh
Offline
Posts: 11
Joined: September 6th, 2011, 7:54 am

Re: [DONE] GeoIP Country Login Message

Post by Kitteh »

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 :(
-->&<-- Forbidden :O

Jonty800
Offline
Posts: 280
Joined: August 21st, 2011, 6:31 am
Location: United Kingdom
Contact:

Re: [DONE] GeoIP Country Login Message

Post by Jonty800 »

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 =)
You cannot use certain BBCodes: [img].

ven000m
Offline
Posts: 31
Joined: May 25th, 2011, 1:14 am

Re: [DONE] GeoIP Country Login Message

Post by ven000m »

Its working for me :P.
Thanks dude!

Locked