/// <summary> /// Sends a normal message to game /// </summary> /// <param name="user"></param> /// <param name="message"></param> public void SendMessageToGame(User user, string message) { this.SendToGame(String.Format("[{0}] <{1}>: {2}", this.Type, user.Nick, IrcHelper.IRCToClassic(message))); }
private void Read() { string line; this.isRunning = true; Logger.Log("Connecting to IRC..."); try { this.SendUserInfo(); while (this.isRunning) { line = this.reader.ReadLine(); if (line == null) { return; } List <object> data = IrcHelper.Parse(line, this); List <string> cmd = (List <string>)data[0]; User user = (User)data[1]; if (cmd[0] == "ERROR") // DEATH { if (!this.isConnected) { this.connectError++; } this.isRunning = false; this.isErrored = true; this.isConnected = false; //TODO: ATTEMPT RECONNECT } switch (cmd[0]) { case "004": // registered with server this.isConnected = true; this.connectError = 0; // do we have a password? if (this.password != null) { this.SendMessage("NickServ", "IDENTIFY " + this.password); this.nickServId = true; } // FOR GEEKSHED SERVERS: I AM A BOT. NOT A MAN. this.SendRaw("MODE " + this.Nick + " +B"); // Join channels this.SendRaw("JOIN " + this.Channel); if (this.OpChannel != null) { this.SendRaw("JOIN " + this.OpChannel); } Logger.Log("Connected to IRC!"); break; case "433": // nick already in use //TODO break; case "473": // cannot join channel //TODO break; case "PING": this.SendRaw("PONG " + cmd[1]); break; case "PRIVMSG": if (cmd[1] == this.Nick) { //TODO } if (cmd[1].StartsWith("#")) { if (cmd[2].StartsWith(this.CommandStarter)) { string c = cmd[2].Remove(0, 1); if (this.commands.ContainsKey(c)) { this.commands[c](cmd[2].Split(' ').Skip(1).ToArray()); } } else { if (cmd[2][0] == 0x001 && cmd[2][cmd[2].Length - 1] == 0x001) { this.SendActionToGame(user, cmd[2].Substring(7).Trim()); } else { this.SendMessageToGame(user, cmd[2]); } } } break; case "KICK": break; case "NICK": break; case "PART": break; case "JOIN": break; } } } catch (Exception e) { Logger.LogError(e); } }