EE2IRC is a relay client that allows communication between EE and IRC users.
▼How it is supposed to work
It connects to an specified EE world using a pre-defined EE account, then it joins a specified channel at the IRC server Frogbox, with a pre-defined name.
Then, any chat message sent on EE will be sent by the client to the IRC channel, as well as backwards.
▼Source code
I have written the code to be the most user-friendly possible, by creating individual classes (EE and IRC) and events, instead of creating all the process into a single void.
▼Program.cs
For now, the chat messages sent on EE are just written on the console, as the IRC class has not been implemented yet.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using PlayerIOClient;
namespace EE2IRC {
public static class User {
public static string world, channel;
public static int client;
}
class Program {
public static void Init () {
Console.Write ("Welcome to EE2IRC.\nIntroduce the world ID: ");
string w = Console.ReadLine ();
Console.Clear ();
while ((!w.StartsWith ("PW") && !w.StartsWith ("BW")) || !w.EndsWith ("I")) {
Console.Write ("Invalid world ID. A valid world ID starts with PW/BW (no open worlds allowed) and ends with I.\nIntroduce the world ID: ");
w = Console.ReadLine ();
Console.Clear ();
}
User.world = w;
Console.Write ("World ID introduced successfully.\nIntroduce the IRC channel: ");
string c = Console.ReadLine ();
Console.Clear ();
while (!c.StartsWith ("#")) {
Console.Write ("Invalid channel. A valid channel starts with #.\nIntroduce the IRC channel: ");
c = Console.ReadLine ();
Console.Clear ();
}
User.channel = c;
User.client = new Random ().Next (1, 4);
}
public static void Connect () {
Console.WriteLine ("World ID: {0}\nIRC Channel: {1}\n\n", User.world, User.channel);
try {
Console.WriteLine ("Connecting to EE...");
EE ee = new EE (User.world, User.channel, User.client);
Console.WriteLine ("Connected to EE. Connecting to Frogbox...");
IRC irc = new IRC ();
Console.WriteLine ("Connected to Frogbox. Client is now ready.\n");
ee.OnUserSay += (sender, user, message) => {
Console.WriteLine ("[EE] <{0}> {1}", user, message);
};
} catch (Exception ex) {
Console.WriteLine ("Something went wrong. Error: " + ex.Message);
return;
}
Thread.Sleep (-1);
}
public static void Main () {
Init ();
Connect ();
Console.ReadKey (true);
}
}
}
▼EE.cs
This class was made specifically to avoid writing all this complex code on a single connect void at Program. It has an event for when someone sends a chat message, so that Program catches it and then sends the message to the IRC (not implemented yet).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PlayerIOClient;
namespace EE2IRC {
public delegate void EEOnUserSayEventHandler (object sender, string user, string message);
class EE {
private Client cli;
private Connection con;
private string[] players = new string[0];
private bool connected = false;
private int clientID;
public event EEOnUserSayEventHandler OnUserSay;
public void Say (string user, string message) => con.Send ("say", string.Format ("[IRC] <{0}> {1}", user, message));
public EE (string world, string channel, int client) {
cli = PlayerIO.QuickConnect.SimpleConnect ("everybody-edits-su9rn58o40itdbnw69plyw", "ee2irc-" + client + "@habbogame.890m.com", "ee2irc-" + client, null);
con = cli.Multiplayer.JoinRoom (world, null);
con.Send ("init");
con.OnMessage += (sender, e) => {
switch (e.Type) {
case "init":
clientID = e.GetInt (5);
con.Send ("init2");
break;
case "init2":
connected = true;
break;
case "add":
if (e.GetInt (0) >= players.Length) Array.Resize (ref players, e.GetInt (0) + 100);
players[e.GetInt (0)] = e.GetString (1);
break;
case "say":
if (connected && e.GetInt (0) != clientID) OnUserSay (this, players[e.GetInt (0)], e.GetString (1));
break;
}
};
con.OnDisconnect += (sender, reason) => { throw new Exception ("Lost connection to the world."); };
}
}
}
▼IRC.cs
I need to learn how the IRC protocol works before implementing the class. For now, it only has an useless event (for when someone sends a message on the channel).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
namespace EE2IRC {
public delegate void IRCOnUserSayEventHandler (object sender, string user, string message);
class IRC {
public event IRCOnUserSayEventHandler OnUserSay;
public IRC () {
}
}
}