Determine players country on login. v.1

Determine players country on login. v.1

Postby Leeizazombie » 20 Jan 2014, 00:36

I've been trying to get this working for a while, and here is my first version!
It uses the players IP address and sends it to a website, where the website will return the IP's country information to Minecraft and display it when a player joins!
Hope you like it! <ok> (I havn't been able to test online with a few players)

Code:
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
using System.Xml.Serialization;
using System.Xml;

namespace MCDzienny
{
    public class CmdPushed : Command
    {
        public override string name { get { return ""; } }
        public override string shortcut { get { return ""; } }
        public override string type { get { return ""; } }
        public override bool museumUsable { get { return false; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
        public override void Use(Player p, string message)
        {
        }

        public override void Init()
        {
            Player.Joined += (object sender, PlayerEventArgs e) =>
            {
                string userIP = e.Player.ip;
                string apiKey = "5d3d0cdbc95df34b9db4a7b4fb754e738bce4ac914ca8909ace8d3ece39cee3b";
                string url = "http://api.ipinfodb.com/v3/ip-country/?key=" + apiKey + "&ip=" + userIP;
                WebRequest request = WebRequest.Create(url);
                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    Encoding encoding = response.CharacterSet != null ? Encoding.GetEncoding(response.CharacterSet) : null;

                    using (var sr = encoding != null ? new StreamReader(response.GetResponseStream(), encoding) :
                                                       new StreamReader(response.GetResponseStream(), true))
                    {
                        var response2 = sr.ReadToEnd();
                        var parts = response2.Split(';');

                        if (parts.Length != 5)
                        {
                            throw new Exception();
                        }

                        string okError = parts[0];
                        string message_ = parts[1];
                        string ip = parts[2];
                        string code = parts[3];
                        string country = parts[4];
                        if (country == "-" || country == null || country == "")
                        {
                            return;
                        }
                        else
                        {
                            Player.GlobalMessage(Server.DefaultColor + "has joined from: %a" + country);
                            /*Player.SendMessage(e.Player, Server.DefaultColor + "Code: %a" + code);
                            Player.SendMessage(e.Player, Server.DefaultColor + "Message: %a" + message_);
                            Player.SendMessage(e.Player, Server.DefaultColor + "IP Address: %a" + ip);*/
                        }
                    }

                }
            };
        }

        public override void Help(Player p)
        {
            Player.SendMessage(p, "");
        }
    }
}


Please give suggestions! :P
Next update plans:
+ Detect country from a list of country codes and make it not show all caps.
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.

Re: Determine players country on login. v.1

Postby ismellike » 20 Jan 2014, 04:46

If this works like you say it does, this is probably one of your best commands <ok>
Working with websites seems to be your thing :p.
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: Determine players country on login. v.1

Postby Leeizazombie » 20 Jan 2014, 12:09

ismellike wrote:If this works like you say it does, this is probably one of your best commands <ok>
Working with websites seems to be your thing :p.

Thank you :P My first code was HTML!
I'm adding more than 200 country codes for my next update, it's taking forever :lol:
EG:
Code: Select all
if (code == "AU") { country = "Austrailia"; }

Without that code it will show "AUSTRAILIA" instead of "Austrailia".
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.

Re: Determine players country on login. v.1

Postby anoniemspy700 » 20 Jan 2014, 14:22

Wow thanks Lee! This will be really usefull since I can now see if the people are dutch :P I now know how to greet them! :D
Join My Lava Survival! [NL]Dutch Lava Survival[NL]
On during day, off during night...(who plays at night?)
User avatar
anoniemspy700
 
Posts: 5
Joined: 08 Jan 2014, 14:13

Re: Determine players country on login. v.1

Postby HETAL » 20 Jan 2014, 15:56

Nice but be careful, giving out API keys isn't safe.
YOU HAVENT SEEN THE LAST OF ME ISMELLIKE
HETAL
 
Posts: 397
Joined: 24 May 2013, 12:10

Re: Determine players country on login. v.1

Postby lucasds12 » 20 Jan 2014, 17:38

If I remember correctly, this has been from the MCDawn software, and I agree with ismellike, using websites for coding is kind of a thing for you, and I bet the next version is going to be 5x as good as this.
-Lucas
There is only one thing I do in life, that's contributing here.
lucasds12
 
Posts: 334
Joined: 17 Apr 2013, 16:17
Location: In the deep caves.

Re: Determine players country on login. v.1

Postby Leeizazombie » 20 Jan 2014, 18:02

HETAL wrote:Nice but be careful, giving out API keys isn't safe.

This isn't a personal API key, it was out in public.
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.

Re: Determine players country on login. v.1

Postby Leeizazombie » 20 Jan 2014, 18:07

lucasds12 wrote:If I remember correctly, this has been from the MCDawn software, and I agree with ismellike, using websites for coding is kind of a thing for you, and I bet the next version is going to be 5x as good as this.
-Lucas

Yes but MCDawn uses a GeoIP system, this is different because it's from an API.
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.

Re: Determine players country on login. v.1

Postby Leeizazombie » 20 Jan 2014, 19:00

The command is accidently called "CmdPushed", Althought I will have all these fixed in my next update
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.

Re: Determine players country on login. v.1

Postby joppiesaus » 21 Jan 2014, 08:13

Really well done! I've tried it to, but couldn't find API keys / website was broken. This is just awesome! :D
joppiesaus
 
Posts: 379
Joined: 20 Aug 2012, 07:28
Location: in a obsedian house, with glass in it so i can see the lava!

Next

Return to Custom Commands

Who is online

Users browsing this forum: No registered users and 2 guests

cron