by Breakdown901 » 16 Aug 2013, 16:51
Ik this has been requested a thousand times, but it could be possible to make as a command. I've found some code in MCLawl, maybe that could help.
- Code: Select all
/*
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl) Licensed under the
Educational Community License, Version 2.0 (the "License"); you may
not use this file except in compliance with the License. You may
obtain a copy of the License at
http://www.osedu.org/licenses/ECL-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the License for the specific language governing
permissions and limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Text;
using Meebey.SmartIrc4net;
using System.Threading;
namespace MCLawl
{
class IRCBot
{
static IrcClient irc = new IrcClient();
static string server = Server.ircServer;
static string channel = Server.ircChannel;
static string opchannel = Server.ircOpChannel;
static string nick = Server.ircNick;
static Thread ircThread;
static string[] names;
public IRCBot()
{
// The IRC Bot must run in a seperate thread, or else the server will freeze.
ircThread = new Thread(new ThreadStart(delegate
{
// Attach event handlers
irc.OnConnecting += new EventHandler(OnConnecting);
irc.OnConnected += new EventHandler(OnConnected);
irc.OnChannelMessage += new IrcEventHandler(OnChanMessage);
irc.OnJoin += new JoinEventHandler(OnJoin);
irc.OnPart += new PartEventHandler(OnPart);
irc.OnQuit += new QuitEventHandler(OnQuit);
irc.OnNickChange += new NickChangeEventHandler(OnNickChange);
irc.OnDisconnected += new EventHandler(OnDisconnected);
irc.OnQueryMessage += new IrcEventHandler(OnPrivMsg);
irc.OnNames += new NamesEventHandler(OnNames);
irc.OnChannelAction += new ActionEventHandler(OnAction);
// Attempt to connect to the IRC server
try { irc.Connect(server, Server.ircPort); }
catch (Exception ex) { Console.WriteLine("Unable to connect to IRC server: {0}", ex.Message); }
}));
ircThread.Start();
}
// While connecting
void OnConnecting(object sender, EventArgs e)
{
Server.s.Log("Connecting to IRC");
}
// When connected
void OnConnected(object sender, EventArgs e)
{
Server.s.Log("Connected to IRC");
irc.Login(nick, nick, 0, nick);
// Check to see if we want to register our bot with nickserv
if (Server.ircIdentify && Server.ircPassword != string.Empty)
{
Server.s.Log("Identifying with Nickserv");
irc.SendMessage(SendType.Message, "nickserv", "IDENTIFY " + Server.ircPassword);
}
Server.s.Log("Joining channels");
irc.RfcJoin(channel);
irc.RfcJoin(opchannel);
irc.Listen()
}
void OnNames(object sender, NamesEventArgs e)
{
names = e.UserList;
}
void OnDisconnected(object sender, EventArgs e)
{
try { irc.Connect(server, 6667); }
catch { Console.WriteLine("Failed to reconnect to IRC"); }
}
// On public channel message
void OnChanMessage(object sender, IrcEventArgs e)
{
string temp = e.Data.Message; string storedNick = e.Data.Nick;
string allowedchars = "1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./!@#$%^*()_+QWERTYUIOPASDFGHJKL:\"ZXCVBNM<>? ";
foreach (char ch in temp)
{
if (allowedchars.IndexOf(ch) == -1)
temp = temp.Replace(ch.ToString(), "*");
}
if (e.Data.Channel == opchannel)
{
Server.s.Log("[(Op) IRC] " + e.Data.Nick + ": " + temp);
Player.GlobalMessageOps(Server.IRCColour + "[(Op) IRC] " + storedNick + ": &f" + temp);
}
else
{
Server.s.Log("[IRC] " + e.Data.Nick + ": " + temp);
Player.GlobalChat(null, Server.IRCColour + "[IRC] " + storedNick + ": &f" + temp, false);
}
//if (temp.IndexOf(':') < temp.IndexOf(' ')) {
// storedNick = temp.Substring(0, temp.IndexOf(':'));
// temp = temp.Substring(temp.IndexOf(' ') + 1);
//}
//s.Log("IRC: " + e.Data.Nick + ": " + e.Data.Message);
//Player.GlobalMessage("IRC: &1" + e.Data.Nick + ": &f" + e.Data.Message);
}
// When someone joins the IRC
void OnJoin(object sender, JoinEventArgs e)
{
Server.s.Log(e.Data.Nick + " has joined channel " + e.Data.Channel);
if (e.Data.Channel == opchannel)
{
Player.GlobalChat(null, Server.IRCColour + e.Data.Nick + Server.DefaultColor + " has joined the operator channel", false);
}
else
{
Player.GlobalChat(null, Server.IRCColour + e.Data.Nick + Server.DefaultColor + " has joined the channel", false);
}
irc.RfcNames(channel);
irc.RfcNames(opchannel);
}
// When someone leaves the IRC
void OnPart(object sender, PartEventArgs e)
{
Server.s.Log(e.Data.Nick + " has left channel " + e.Data.Channel);
if (e.Data.Channel == opchannel)
{
Player.GlobalChat(null, Server.IRCColour + e.Data.Nick + Server.DefaultColor + " has left the operator channel", false);
}
else
{
Player.GlobalChat(null, Server.IRCColour + e.Data.Nick + Server.DefaultColor + " has left the channel", false);
}
irc.RfcNames(channel);
irc.RfcNames(opchannel);
}
Owner of:
Breakdown901 Lava Survival/Zombie Survival/Freebuild
Host of NeonGaming Lava Survival.