12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820 |
- /*
- * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *
- * SVN: $Id$
- */
-
- package org.ownage.dmdirc.parser;
-
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.PrintWriter;
- import java.net.Socket;
- import java.net.UnknownHostException;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Hashtable;
- import java.util.Enumeration;
-
- /**
- * IRC Parser.
- *
- * @author Shane Mc Cormack
- * @version $Id$
- */
- public class IRCParser implements Runnable {
-
- public static final int ndInfo = 1; // Information
- public static final int ndSocket = 2; // Socket Errors
- // public static final int ndSomething = 4; //Next thingy
-
- public static final int errFatal = 1; // Error is potentially Fatal. Desync 99% Guarenteed!
- public static final int errError = 2; // Error is not fatal, but is more severe than a warning
- public static final int errWarning = 4; // This was an unexpected occurance, but shouldn't be anything to worry about
- public static final int errCanContinue = 8; // If an Error has this flag, it means the parser is able to continue running
- // Most errWarnings should have this flag. if Fatal or Error are not accomanied
- // with this flag, you should disconnect or risk problems further on.
-
- // Development Debugging info - Outputs directly to console.
- // This is used for debugging info that is generally of no use to most people
- // If this is set to false, self-test and any the "useless" debugging that relies on
- // this being true are not compiled.
- protected static final boolean bDebug = true;
-
- private Socket socket = null;
- private PrintWriter out = null;
- private BufferedReader in = null;
-
- public MyInfo me = new MyInfo(); // This is what the user wants, nickname here is *not* fact.
- public ServerInfo server = new ServerInfo(); // Server Info requested by user
-
- protected String sServerName;
-
- protected String sThinkNickname; // This is what we want the nickname to be.
- protected boolean TriedAlt = false;
-
- protected boolean Got001 = false;
- protected boolean HasBegan = false;
- protected boolean IsFirst = true;
-
- // Better alternative to hashtable?
- // Valid Boolean Modes are stored as Hashtable.pub('m',1); where 'm' is the mode and 1 is a numeric value
- // Numeric values are powers of 2. This allows up to 32 modes at present (expandable to 64)
- // ChannelInfo/ChannelClientInfo etc provide methods to view the modes in a human way.
- // PrefixModes are o/v etc Prefix map contains 2 pairs for each mode. (eg @ => o and o => @)
- protected Hashtable<Character,Integer> hPrefixModes = new Hashtable<Character,Integer>();
- protected Hashtable<Character,Character> hPrefixMap = new Hashtable<Character,Character>();
- protected int nNextKeyPrefix = 1;
- protected Hashtable<Character,Integer> hUserModes = new Hashtable<Character,Integer>();
- protected int nNextKeyUser = 1;
- protected Hashtable<Character,Integer> hChanModesBool = new Hashtable<Character,Integer>();
- protected int nNextKeyCMBool = 1;
- // Non Boolean Modes (for Channels) are stored together in this arraylist, the value param
- // is used to show the type of variable. (List (1), Param just for set (2), Param for Set and Unset (2+4=6))
- protected Hashtable<Character,Byte> hChanModesOther = new Hashtable<Character,Byte>();
- protected static final byte cmList = 1;
- protected static final byte cmSet = 2;
- protected static final byte cmUnset = 4;
-
- // Channel Prefixs
- // The value for these is always true.
- protected Hashtable<Character,Boolean> hChanPrefix = new Hashtable<Character,Boolean>();
-
- protected Hashtable<String,ClientInfo> hClientList = new Hashtable<String,ClientInfo>();
- protected Hashtable<String,ChannelInfo> hChannelList = new Hashtable<String,ChannelInfo>();
- protected ClientInfo cMyself = null;
-
- protected Hashtable<String,String> h005Info = new Hashtable<String,String>();
-
- // Events
- // TODO: This would probably be more efficient as hashtables.
- public interface IDebugInfo { public void onDebug(IRCParser tParser, int nLevel, String sData); }
- ArrayList<IDebugInfo> cbDebugInfo = new ArrayList<IDebugInfo>();
- public interface IMOTDEnd { public void onMOTDEnd(IRCParser tParser); }
- ArrayList<IMOTDEnd> cbEndOfMOTD = new ArrayList<IMOTDEnd>();
- public interface IDataIn { public void onDataIn(IRCParser tParser, String sData); }
- ArrayList<IDataIn> cbDataIn = new ArrayList<IDataIn>();
- public interface IDataOut { public void onDataOut(IRCParser tParser, String sData, boolean FromParser); }
- ArrayList<IDataOut> cbDataOut = new ArrayList<IDataOut>();
- public interface INickInUse { public void onNickInUse(IRCParser tParser); }
- ArrayList<INickInUse> cbNickInUse = new ArrayList<INickInUse>();
- public interface IErrorInfo { public void onError(IRCParser tParser, int nLevel, String sData); }
- ArrayList<IErrorInfo> cbErrorInfo = new ArrayList<IErrorInfo>();
- public interface IChannelJoin { public void onJoinChannel(IRCParser tParser, ChannelInfo cChannel, ChannelClientInfo cChannelClient ); }
- ArrayList<IChannelJoin> cbChannelJoin = new ArrayList<IChannelJoin>();
- public interface IChannelPart { public void onPartChannel(IRCParser tParser, ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sReason ); }
- ArrayList<IChannelPart> cbChannelPart = new ArrayList<IChannelPart>();
- public interface IChannelQuit { public void onQuitChannel(IRCParser tParser, ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sReason ); }
- ArrayList<IChannelQuit> cbChannelQuit = new ArrayList<IChannelQuit>();
- public interface IChannelTopic { public void onTopic(IRCParser tParser, ChannelInfo cChannel, boolean bIsNewTopic); }
- ArrayList<IChannelTopic> cbChannelTopic = new ArrayList<IChannelTopic>();
- public interface IChannelModesChanged { public void onModeChange(IRCParser tParser, ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sHost); }
- ArrayList<IChannelModesChanged> cbChannelModesChanged = new ArrayList<IChannelModesChanged>();
- public interface IUserModesChanged { public void onUserModeChange(IRCParser tParser, ClientInfo cClient, String sSetBy); }
- ArrayList<IUserModesChanged> cbUserModesChanged = new ArrayList<IUserModesChanged>();
- public interface INickChanged { public void onNickChanged(IRCParser tParser, ClientInfo cClient, String sOldNick); }
- ArrayList<INickChanged> cbNickChanged = new ArrayList<INickChanged>();
- public interface IChannelKick { public void onChannelKick(IRCParser tParser, ChannelInfo cChannel, ChannelClientInfo cKickedClient, ChannelClientInfo cKickedByClient, String sReason, String sKickedByHost); }
- ArrayList<IChannelKick> cbChannelKick = new ArrayList<IChannelKick>();
- public interface IChannelMessage { public void onChannelMessage(IRCParser tParser, ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sMessage, String sHost ); }
- ArrayList<IChannelMessage> cbChannelMessage = new ArrayList<IChannelMessage>();
- public interface IChannelAction { public void onChannelAction(IRCParser tParser, ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sMessage, String sHost ); }
- ArrayList<IChannelAction> cbChannelAction = new ArrayList<IChannelAction>();
- public interface IChannelNotice { public void onChannelNotice(IRCParser tParser, ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sMessage, String sHost ); }
- ArrayList<IChannelNotice> cbChannelNotice = new ArrayList<IChannelNotice>();
- public interface IPrivateMessage { public void onPrivateMessage(IRCParser tParser, ClientInfo cClient, String sMessage, String sHost ); }
- ArrayList<IPrivateMessage> cbPrivateMessage = new ArrayList<IPrivateMessage>();
- public interface IPrivateAction { public void onPrivateAction(IRCParser tParser, ClientInfo cClient, String sMessage, String sHost ); }
- ArrayList<IPrivateAction> cbPrivateAction = new ArrayList<IPrivateAction>();
- public interface IPrivateNotice { public void onPrivateNotice(IRCParser tParser, ClientInfo cClient, String sMessage, String sHost ); }
- ArrayList<IPrivateNotice> cbPrivateNotice = new ArrayList<IPrivateNotice>();
- public interface IUnknownMessage { public void onUnknownMessage(IRCParser tParser, ClientInfo cClient, String sMessage, String sHost ); }
- ArrayList<IUnknownMessage> cbUnknownMessage = new ArrayList<IUnknownMessage>();
- public interface IUnknownAction { public void onUnknownAction(IRCParser tParser, ClientInfo cClient, String sMessage, String sHost ); }
- ArrayList<IUnknownAction> cbUnknownAction = new ArrayList<IUnknownAction>();
- public interface IUnknownNotice { public void onUnknownNotice(IRCParser tParser, ClientInfo cClient, String sMessage, String sHost ); }
- ArrayList<IUnknownNotice> cbUnknownNotice = new ArrayList<IUnknownNotice>();
- public interface IChannelCTCP { public void onChannelCTCP(IRCParser tParser, ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sType, String sMessage, String sHost ); }
- ArrayList<IChannelCTCP> cbChannelCTCP = new ArrayList<IChannelCTCP>();
- public interface IPrivateCTCP { public void onPrivateCTCP(IRCParser tParser, ClientInfo cClient, String sType, String sMessage, String sHost ); }
- ArrayList<IPrivateCTCP> cbPrivateCTCP = new ArrayList<IPrivateCTCP>();
- public interface IUnknownCTCP { public void onUnknownCTCP(IRCParser tParser, ClientInfo cClient, String sType, String sMessage, String sHost ); }
- ArrayList<IUnknownCTCP> cbUnknownCTCP = new ArrayList<IUnknownCTCP>();
- public interface IChannelCTCPReply { public void onChannelCTCPReply(IRCParser tParser, ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sType, String sMessage, String sHost ); }
- ArrayList<IChannelCTCPReply> cbChannelCTCPReply = new ArrayList<IChannelCTCPReply>();
- public interface IPrivateCTCPReply { public void onPrivateCTCPReply(IRCParser tParser, ClientInfo cClient, String sType, String sMessage, String sHost ); }
- ArrayList<IPrivateCTCPReply> cbPrivateCTCPReply = new ArrayList<IPrivateCTCPReply>();
- public interface IUnknownCTCPReply { public void onUnknownCTCPReply(IRCParser tParser, ClientInfo cClient, String sType, String sMessage, String sHost ); }
- ArrayList<IUnknownCTCPReply> cbUnknownCTCPReply = new ArrayList<IUnknownCTCPReply>();
- public interface IQuit { public void onQuit(IRCParser tParser, ClientInfo cClient, String sReason ); }
- ArrayList<IQuit> cbQuit = new ArrayList<IQuit>();
- public interface IGotNames { public void onGotNames(IRCParser tParser, ChannelInfo cChannel); }
- ArrayList<IGotNames> cbGotNames = new ArrayList<IGotNames>();
-
-
- @SuppressWarnings("unchecked")
- private void AddCallback(Object eMethod, ArrayList CallbackList) {
- for (int i = 0; i < CallbackList.size(); i++) {
- if (eMethod.equals(CallbackList.get(i))) { return; }
- }
- CallbackList.add(eMethod);
- }
- private void DelCallback(Object eMethod, ArrayList CallbackList) {
- for (int i = 0; i < CallbackList.size(); i++) {
- if (eMethod.equals(CallbackList.get(i))) { CallbackList.remove(i); break; }
- }
- }
-
- /**
- * Add callback for DebugInfo (onDebug).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddDebugInfo(Object eMethod) { AddCallback(eMethod, cbDebugInfo); }
- /**
- * Delete callback for DebugInfo (onDebug).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelDebugInfo(Object eMethod) { DelCallback(eMethod, cbDebugInfo); }
- protected boolean CallDebugInfo(int level, String data) {
- if (bDebug) { System.out.printf("[DEBUG] {%d} %s\n", level, data); }
- boolean bResult = false;
- for (int i = 0; i < cbDebugInfo.size(); i++) {
- cbDebugInfo.get(i).onDebug(this, level, data);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for MOTDEnd (onMOTDEnd).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddMOTDEnd(Object eMethod) { AddCallback(eMethod, cbEndOfMOTD); }
- /**
- * Delete callback for MOTDEnd (onMOTDEnd).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelMOTDEnd(Object eMethod) { DelCallback(eMethod, cbEndOfMOTD); }
- protected boolean CallMOTDEnd() {
- boolean bResult = false;
- for (int i = 0; i < cbEndOfMOTD.size(); i++) {
- cbEndOfMOTD.get(i).onMOTDEnd(this);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for DataIn (onDataIn).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddDataIn(Object eMethod) { AddCallback((IDataIn)eMethod, cbDataIn); }
- /**
- * Delete callback for DataIn (onDebug).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelDataIn(Object eMethod) { DelCallback((IDataIn)eMethod, cbDataIn); }
- protected boolean CallDataIn(String data) {
- boolean bResult = false;
- for (int i = 0; i < cbDataIn.size(); i++) {
- cbDataIn.get(i).onDataIn(this, data);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for DataOut (onDataOut).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddDataOut(Object eMethod) { AddCallback((IDataOut)eMethod, cbDataOut); }
- /**
- * Delete callback for DataOut (onDataOut).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelDataOut(Object eMethod) { DelCallback((IDataOut)eMethod, cbDataOut); }
- protected boolean CallDataOut(String data, boolean FromParser) {
- boolean bResult = false;
- for (int i = 0; i < cbDataOut.size(); i++) {
- cbDataOut.get(i).onDataOut(this, data, FromParser);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for NickInUse (onNickInUse).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddNickInUse(Object eMethod) { AddCallback(eMethod, cbNickInUse); }
- /**
- * Delete callback for NickInUse (onNickInUse).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelNickInUse(Object eMethod) { DelCallback(eMethod, cbNickInUse); }
- protected boolean CallNickInUse() {
- boolean bResult = false;
- for (int i = 0; i < cbNickInUse.size(); i++) {
- cbNickInUse.get(i).onNickInUse(this);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for ErrorInfo (onError).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddErrorInfo(Object eMethod) { AddCallback(eMethod, cbErrorInfo); }
- /**
- * Delete callback for ErrorInfo (onError).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelErrorInfo(Object eMethod) { DelCallback(eMethod, cbErrorInfo); }
- protected boolean CallErrorInfo(int level, String data) {
- if (bDebug) { System.out.printf("[ERROR] {%d} %s\n", level, data); }
- boolean bResult = false;
- for (int i = 0; i < cbErrorInfo.size(); i++) {
- cbErrorInfo.get(i).onError(this, level, data);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for ChannelJoin (onJoinChannel).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddChannelJoin(Object eMethod) { AddCallback(eMethod, cbChannelJoin); }
- /**
- * Delete callback for ChannelJoin (onJoinChannel).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelChannelJoin(Object eMethod) { DelCallback(eMethod, cbChannelJoin); }
- protected boolean CallChannelJoin(ChannelInfo cChannel, ChannelClientInfo cChannelClient) {
- boolean bResult = false;
- for (int i = 0; i < cbChannelJoin.size(); i++) {
- cbChannelJoin.get(i).onJoinChannel(this, cChannel, cChannelClient);
- bResult = true;
- }
- return bResult;
- }
-
-
- /**
- * Add callback for ChannelPart (onPartChannel).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddChannelPart(Object eMethod) { AddCallback(eMethod, cbChannelPart); }
- /**
- * Delete callback for ChannelPart (onPartChannel).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelChannelPart(Object eMethod) { DelCallback(eMethod, cbChannelPart); }
- protected boolean CallChannelPart(ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sReason) {
- boolean bResult = false;
- for (int i = 0; i < cbChannelPart.size(); i++) {
- cbChannelPart.get(i).onPartChannel(this, cChannel, cChannelClient, sReason);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for ChannelQuit (onQuitChannel).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddChannelQuit(Object eMethod) { AddCallback(eMethod, cbChannelQuit); }
- /**
- * Delete callback for ChannelQuit (onQuitChannel).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelChannelQuit(Object eMethod) { DelCallback(eMethod, cbChannelQuit); }
- protected boolean CallChannelQuit(ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sReason) {
- boolean bResult = false;
- for (int i = 0; i < cbChannelQuit.size(); i++) {
- cbChannelQuit.get(i).onQuitChannel(this, cChannel, cChannelClient, sReason);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for Quit (onQuit).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddQuit(Object eMethod) { AddCallback(eMethod, cbQuit); }
- /**
- * Delete callback for Quit (onQuit).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelQuit(Object eMethod) { DelCallback(eMethod, cbQuit); }
- protected boolean CallQuit(ClientInfo cClient, String sReason) {
- boolean bResult = false;
- for (int i = 0; i < cbQuit.size(); i++) {
- cbQuit.get(i).onQuit(this, cClient, sReason);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for ChannelTopic (onTopic).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddTopic(Object eMethod) { AddCallback(eMethod, cbChannelTopic); }
- /**
- * Delete callback for ChannelTopic (onTopic).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelTopic(Object eMethod) { DelCallback(eMethod, cbChannelTopic); }
- protected boolean CallTopic(ChannelInfo cChannel, boolean bIsJoinTopic) {
- boolean bResult = false;
- for (int i = 0; i < cbChannelTopic.size(); i++) {
- cbChannelTopic.get(i).onTopic(this, cChannel, bIsJoinTopic);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for ChannelModesChanged (onModeChange).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddModesChanged(Object eMethod) { AddCallback(eMethod, cbChannelModesChanged); }
- /**
- * Delete callback for ChannelModesChanged (onModeChange).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelModesChanged(Object eMethod) { DelCallback(eMethod, cbChannelModesChanged); }
- protected boolean CallModesChanged(ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sHost) {
- boolean bResult = false;
- for (int i = 0; i < cbChannelModesChanged.size(); i++) {
- cbChannelModesChanged.get(i).onModeChange(this, cChannel, cChannelClient, sHost);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for UserModesChanged (onUserModeChange).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddUserModesChanged(Object eMethod) { AddCallback(eMethod, cbUserModesChanged); }
- /**
- * Delete callback for UserModesChanged (onUserModeChange).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelUserModesChanged(Object eMethod) { DelCallback(eMethod, cbUserModesChanged); }
- protected boolean CallUserModesChanged(ClientInfo cClient, String sSetby) {
- boolean bResult = false;
- for (int i = 0; i < cbUserModesChanged.size(); i++) {
- cbUserModesChanged.get(i).onUserModeChange(this, cClient, sSetby);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for UserNickChanged (onNickChanged).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddNickChanged(Object eMethod) { AddCallback(eMethod, cbNickChanged); }
- /**
- * Delete callback for UserNickChanged (onNickChanged).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelNickChanged(Object eMethod) { DelCallback(eMethod, cbNickChanged); }
- protected boolean CallNickChanged(ClientInfo cClient, String sOldNick) {
- boolean bResult = false;
- for (int i = 0; i < cbNickChanged.size(); i++) {
- cbNickChanged.get(i).onNickChanged(this, cClient, sOldNick);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for ChannelKick (onChannelKick).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddChannelKick(Object eMethod) { AddCallback(eMethod, cbChannelKick); }
- /**
- * Delete callback for ChannelKick (onChannelKick).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelChannelKick(Object eMethod) { DelCallback(eMethod, cbChannelKick); }
- protected boolean CallChannelKick(ChannelInfo cChannel, ChannelClientInfo cKickedClient, ChannelClientInfo cKickedByClient, String sReason, String sKickedByHost) {
- boolean bResult = false;
- for (int i = 0; i < cbChannelKick.size(); i++) {
- cbChannelKick.get(i).onChannelKick(this, cChannel, cKickedClient, cKickedByClient, sReason, sKickedByHost);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for ChannelMessage (onChannelMessage).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddChannelMessage(Object eMethod) { AddCallback(eMethod, cbChannelMessage); }
- /**
- * Delete callback for ChannelMessage (onChannelMessage).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelChannelMessage(Object eMethod) { DelCallback(eMethod, cbChannelMessage); }
- protected boolean CallChannelMessage(ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sMessage, String sHost) {
- boolean bResult = false;
- for (int i = 0; i < cbChannelMessage.size(); i++) {
- cbChannelMessage.get(i).onChannelMessage(this, cChannel, cChannelClient, sMessage, sHost);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for ChannelAction (onChannelAction).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddChannelAction(Object eMethod) { AddCallback(eMethod, cbChannelAction); }
- /**
- * Delete callback for ChannelAction (onChannelAction).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelChannelAction(Object eMethod) { DelCallback(eMethod, cbChannelAction); }
- protected boolean CallChannelAction(ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sMessage, String sHost) {
- boolean bResult = false;
- for (int i = 0; i < cbChannelAction.size(); i++) {
- cbChannelAction.get(i).onChannelAction(this, cChannel, cChannelClient, sMessage, sHost);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for ChannelNotice (onChannelNotice).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddChannelNotice(Object eMethod) { AddCallback(eMethod, cbChannelNotice); }
- /**
- * Delete callback for ChannelNotice (onChannelNotice).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelChannelNotice(Object eMethod) { DelCallback(eMethod, cbChannelNotice); }
- protected boolean CallChannelNotice(ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sMessage, String sHost) {
- boolean bResult = false;
- for (int i = 0; i < cbChannelNotice.size(); i++) {
- cbChannelNotice.get(i).onChannelNotice(this, cChannel, cChannelClient, sMessage, sHost);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for PrivateMessage (onPrivateMessage).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddPrivateMessage(Object eMethod) { AddCallback(eMethod, cbPrivateMessage); }
- /**
- * Delete callback for PrivateMessage (onPrivateMessage).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelPrivateMessage(Object eMethod) { DelCallback(eMethod, cbPrivateMessage); }
- protected boolean CallPrivateMessage(ClientInfo cClient, String sMessage, String sHost) {
- boolean bResult = false;
- for (int i = 0; i < cbPrivateMessage.size(); i++) {
- cbPrivateMessage.get(i).onPrivateMessage(this, cClient, sMessage, sHost);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for PrivateAction (onPrivateAction).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddPrivateAction(Object eMethod) { AddCallback(eMethod, cbPrivateAction); }
- /**
- * Delete callback for PrivateAction (onPrivateAction).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelPrivateAction(Object eMethod) { DelCallback(eMethod, cbPrivateAction); }
- protected boolean CallPrivateAction(ClientInfo cClient, String sMessage, String sHost) {
- boolean bResult = false;
- for (int i = 0; i < cbPrivateAction.size(); i++) {
- cbPrivateAction.get(i).onPrivateAction(this, cClient, sMessage, sHost);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for PrivateNotice (onPrivateNotice).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddPrivateNotice(Object eMethod) { AddCallback(eMethod, cbPrivateNotice); }
- /**
- * Delete callback for PrivateNotice (onPrivateNotice).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelPrivateNotice(Object eMethod) { DelCallback(eMethod, cbPrivateNotice); }
- protected boolean CallPrivateNotice(ClientInfo cClient, String sMessage, String sHost) {
- boolean bResult = false;
- for (int i = 0; i < cbPrivateNotice.size(); i++) {
- cbPrivateNotice.get(i).onPrivateNotice(this, cClient, sMessage, sHost);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for UnknownMessage (onUnknownMessage).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddUnknownMessage(Object eMethod) { AddCallback(eMethod, cbUnknownMessage); }
- /**
- * Delete callback for UnknownMessage (onUnknownMessage).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelUnknownMessage(Object eMethod) { DelCallback(eMethod, cbUnknownMessage); }
- protected boolean CallUnknownMessage(ClientInfo cClient, String sMessage, String sHost) {
- boolean bResult = false;
- for (int i = 0; i < cbUnknownMessage.size(); i++) {
- cbUnknownMessage.get(i).onUnknownMessage(this, cClient, sMessage, sHost);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for UnknownAction (onUnknownAction).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddUnknownAction(Object eMethod) { AddCallback(eMethod, cbUnknownAction); }
- /**
- * Delete callback for UnknownAction (onUnknownAction).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelUnknownAction(Object eMethod) { DelCallback(eMethod, cbUnknownAction); }
- protected boolean CallUnknownAction(ClientInfo cClient, String sMessage, String sHost) {
- boolean bResult = false;
- for (int i = 0; i < cbUnknownAction.size(); i++) {
- cbUnknownAction.get(i).onUnknownAction(this, cClient, sMessage, sHost);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for UnknownNotice (onUnknownNotice).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddUnknownNotice(Object eMethod) { AddCallback(eMethod, cbUnknownNotice); }
- /**
- * Delete callback for UnknownNotice (onUnknownNotice).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelUnknownNotice(Object eMethod) { DelCallback(eMethod, cbUnknownNotice); }
- protected boolean CallUnknownNotice(ClientInfo cClient, String sMessage, String sHost) {
- boolean bResult = false;
- for (int i = 0; i < cbUnknownNotice.size(); i++) {
- cbUnknownNotice.get(i).onUnknownNotice(this, cClient, sMessage, sHost);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for ChannelCTCP (onChannelCTCP).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddChannelCTCP(Object eMethod) { AddCallback(eMethod, cbChannelCTCP); }
- /**
- * Delete callback for ChannelCTCP (onChannelCTCP).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelChannelCTCP(Object eMethod) { DelCallback(eMethod, cbChannelCTCP); }
- protected boolean CallChannelCTCP(ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sType, String sMessage, String sHost) {
- boolean bResult = false;
- for (int i = 0; i < cbChannelCTCP.size(); i++) {
- cbChannelCTCP.get(i).onChannelCTCP(this, cChannel, cChannelClient, sType, sMessage, sHost);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for PrivateCTCP (onPrivateCTCP).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddPrivateCTCP(Object eMethod) { AddCallback(eMethod, cbPrivateCTCP); }
- /**
- * Delete callback for PrivateCTCP (onPrivateCTCP).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelPrivateCTCP(Object eMethod) { DelCallback(eMethod, cbPrivateCTCP); }
- protected boolean CallPrivateCTCP(ClientInfo cClient, String sType, String sMessage, String sHost) {
- boolean bResult = false;
- for (int i = 0; i < cbPrivateCTCP.size(); i++) {
- cbPrivateCTCP.get(i).onPrivateCTCP(this, cClient, sType, sMessage, sHost);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for UnknownCTCP (onUnknownCTCP).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddUnknownCTCP(Object eMethod) { AddCallback(eMethod, cbUnknownCTCP); }
- /**
- * Delete callback for UnknownCTCP (onUnknownCTCP).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelUnknownCTCP(Object eMethod) { DelCallback(eMethod, cbUnknownCTCP); }
- protected boolean CallUnknownCTCP(ClientInfo cClient, String sType, String sMessage, String sHost) {
- boolean bResult = false;
- for (int i = 0; i < cbUnknownCTCP.size(); i++) {
- cbUnknownCTCP.get(i).onUnknownCTCP(this, cClient, sType, sMessage, sHost);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for ChannelCTCPReply (onChannelCTCPReply).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddChannelCTCPReply(Object eMethod) { AddCallback(eMethod, cbChannelCTCPReply); }
- /**
- * Delete callback for ChannelCTCPReply (onChannelCTCPReply).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelChannelCTCPReply(Object eMethod) { DelCallback(eMethod, cbChannelCTCPReply); }
- protected boolean CallChannelCTCPReply(ChannelInfo cChannel, ChannelClientInfo cChannelClient, String sType, String sMessage, String sHost) {
- boolean bResult = false;
- for (int i = 0; i < cbChannelCTCPReply.size(); i++) {
- cbChannelCTCPReply.get(i).onChannelCTCPReply(this, cChannel, cChannelClient, sType, sMessage, sHost);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for PrivateCTCPReply (onPrivateCTCPReply).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddPrivateCTCPReply(Object eMethod) { AddCallback(eMethod, cbPrivateCTCPReply); }
- /**
- * Delete callback for PrivateCTCPReply (onPrivateCTCPReply).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelPrivateCTCPReply(Object eMethod) { DelCallback(eMethod, cbPrivateCTCPReply); }
- protected boolean CallPrivateCTCPReply(ClientInfo cClient, String sType, String sMessage, String sHost) {
- boolean bResult = false;
- for (int i = 0; i < cbPrivateCTCPReply.size(); i++) {
- cbPrivateCTCPReply.get(i).onPrivateCTCPReply(this, cClient, sType, sMessage, sHost);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for UnknownCTCPReply (onUnknownCTCPReply).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddUnknownCTCPReply(Object eMethod) { AddCallback(eMethod, cbUnknownCTCPReply); }
- /**
- * Delete callback for UnknownCTCPReply (onUnknownCTCPReply).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelUnknownCTCPReply(Object eMethod) { DelCallback(eMethod, cbUnknownCTCPReply); }
- protected boolean CallUnknownCTCPReply(ClientInfo cClient, String sType, String sMessage, String sHost) {
- boolean bResult = false;
- for (int i = 0; i < cbUnknownCTCPReply.size(); i++) {
- cbUnknownCTCPReply.get(i).onUnknownCTCPReply(this, cClient, sType, sMessage, sHost);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Add callback for GotNames (onGotNames).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void AddGotNames(Object eMethod) { AddCallback(eMethod, cbGotNames); }
- /**
- * Delete callback for GotNames (onGotNames).
- *
- * @param eMethod Reference to object that handles the callback
- */
- public void DelGotNames(Object eMethod) { DelCallback(eMethod, cbGotNames); }
- protected boolean CallGotNames(ChannelInfo cChannel) {
- boolean bResult = false;
- for (int i = 0; i < cbGotNames.size(); i++) {
- cbGotNames.get(i).onGotNames(this, cChannel);
- bResult = true;
- }
- return bResult;
- }
-
- /**
- * Perform a silent test on certain functions.
- *
- * @return Boolean result of test. (True only if ALL tests pass)
- */
- public boolean DoSelfTest() {
- return DoSelfTest(true);
- }
-
- /**
- * Perform a test on certain functions.
- *
- * @param bSilent Should output be given? (Sent to Console)
- * @return Boolean result of test. (True only if ALL tests pass)
- */
- public boolean DoSelfTest(boolean bSilent) {
- if (bDebug) {
- boolean bResult = false;
- ParserTestClass ptc = new ParserTestClass();
- if (bSilent) { bResult = ptc.SelfTest(); }
- else {
- System.out.printf(" --------------------\n");
- System.out.printf(" Beginning Tests\n");
- System.out.printf(" --------------------\n");
- ptc.RunTests();
- System.out.printf(" --------------------\n");
- System.out.printf(" End\n");
- System.out.printf(" --------------------\n");
- System.out.printf(" Total Tests: %d\n",ptc.GetTotalTests());
- System.out.printf(" Passed Tests: %d\n",ptc.GetPassedTests());
- System.out.printf(" Failed Tests: %d\n",ptc.GetFailedTests());
- System.out.printf(" --------------------\n");
- bResult = (ptc.GetTotalTests() == ptc.GetPassedTests());
- }
- ptc = null;
- return bResult;
- } else {
- return true;
- }
- }
-
- /**
- * Default constructor.
- */
- public IRCParser() { }
- /**
- * Constructor with ServerInfo.
- *
- * @param serverDetails Server information.
- */
- public IRCParser(ServerInfo serverDetails) { this(null,serverDetails); }
- /**
- * Constructor with MyInfo.
- *
- * @param myDetails Client information.|
- */
- public IRCParser(MyInfo myDetails) { this(myDetails,null); }
- /**
- * Constructor with ServerInfo and MyInfo.
- *
- * @param serverDetails Server information.
- * @param myDetails Client information.|
- */
- public IRCParser(MyInfo myDetails, ServerInfo serverDetails) {
- if (myDetails != null) { this.me = myDetails; }
- if (serverDetails != null) { this.server = serverDetails; }
- }
-
- private void ResetState() {
- // Reset General State info
- TriedAlt = false;
- Got001 = false;
- // Clear the hash tables
- hChannelList.clear();
- hClientList.clear();
- h005Info.clear();
- hPrefixModes.clear();
- hPrefixMap.clear();
- hChanModesOther.clear();
- hChanModesBool.clear();
- hUserModes.clear();
- hChanPrefix.clear();
- // Reset the mode indexes
- nNextKeyPrefix = 1;
- nNextKeyCMBool = 1;
- nNextKeyUser = 1;
- }
-
- private void connect() throws Exception {
- try {
- ResetState();
- CallDebugInfo(ndSocket,"Connecting to "+server.sHost+":"+server.nPort);
- socket = new Socket(server.sHost,server.nPort);
- if (bDebug) { System.out.printf("\t\t-> 1\n"); }
- out = new PrintWriter(socket.getOutputStream(), true);
- if (bDebug) { System.out.printf("\t\t-> 2\n"); }
- in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- if (bDebug) { System.out.printf("\t\t-> 3\n"); }
- } catch (Exception e) { throw e; }
- }
-
- /**
- * Begin execution. Connect to server, and start parsing incomming lines
- */
- public void run() {
- CallDebugInfo(ndInfo,"Begin Thread Execution");
- if (HasBegan) { return; } else { HasBegan = true; }
- try { connect(); } catch (Exception e) { CallDebugInfo(ndSocket,"Error Connecting, Aborted"); return; }
- // :HACK: While true loops really really suck.
- CallDebugInfo(ndSocket,"Socket Connected");
- String line = "";
- while(true) {
- try {
- line = in.readLine(); // Blocking :/
- if (line == null) {
- CallDebugInfo(ndSocket,"Socket Closed");
- break;
- } else {
- if (IsFirst) {
- if (!server.sPassword.equals("")) {
- SendString("PASS "+server.sPassword);
- }
- SetNickname(me.sNickname);
- SendString("USER "+me.sUsername.toLowerCase()+" * * :"+me.sRealname);
- IsFirst = false;
- }
- ProcessLine(line);
- }
- } catch (IOException e) {
- CallDebugInfo(ndSocket,"Socket Closed");
- break;
- }
- }
- CallDebugInfo(ndInfo,"End Thread Execution");
- }
-
- protected void finalize(){
- try {
- socket.close();
- } catch (IOException e) {
- CallDebugInfo(ndInfo,"Could not close socket");
- }
- }
-
- protected String GetParam(String line) {
- String[] params = null;
- params = line.split(" :",2);
- return params[params.length-1];
- }
-
- protected String[] IRCTokenise(String line) {
- if (line == null) {
- String[] tokens = new String[1];
- tokens[0] = "";
- return tokens; // Return empty string[]
- };
- String[] params = null;
- String[] tokens = null;
- params = line.split(" :",2);
- tokens = params[0].split(" ");
- if (params.length == 2) {
- String[] temp = new String[tokens.length+1];
- System.arraycopy(tokens, 0, temp, 0, tokens.length);
- tokens = temp;
- tokens[tokens.length-1] = params[1];
- }
- return tokens;
- }
-
-
- /**
- * Get the ClientInfo object for a person.
- *
- * @param sWho Who can be any valid identifier for a client as long as it contains a nickname (?:)nick(?!ident)(?@host)
- * @return ClientInfo Object for the client, or null
- */
- public ClientInfo GetClientInfo(String sWho) {
- if (bDebug) { System.out.printf("\t\tInput: %s | ",sWho); }
- sWho = ClientInfo.ParseHost(sWho);
- if (bDebug) { System.out.printf("Client Name: %s\n",sWho); }
- sWho = sWho.toLowerCase();
- if (hClientList.containsKey(sWho)) { return hClientList.get(sWho); } else { return null; }
- }
-
- /**
- * Get the ChannelInfo object for a channel.
- *
- * @param sWhat This is the name of the channel.
- * @return ChannelInfo Object for the channel, or null
- */
- public ChannelInfo GetChannelInfo(String sWhat) {
- sWhat = sWhat.toLowerCase();
- if (hChannelList.containsKey(sWhat)) { return hChannelList.get(sWhat); } else { return null; }
- }
-
- /**
- * Send a line to the server.
- *
- * @param line Line to send (\r\n termination is added automatically)
- */
- public void SendLine(String line) { CallDataOut(line,false); out.printf("%s\r\n",line);} // This should do some checks on stuff, public event!
-
- // Our Method
- protected void SendString(String line) {
- CallDataOut(line,true);
- out.printf("%s\r\n",line);
- }
-
-
- private void ProcessLine(String line) {
- String[] token = IRCTokenise(line);
- // String mainParam = token[token.length-1];
-
- int nParam;
- CallDataIn(line);
- String sParam = token[1];
- try {nParam = Integer.parseInt(token[1]);} catch (Exception e) { nParam = -1;}
-
- try {
- if (token[0].equals("PING") || token[1].equals("PING")) { SendString("PONG :"+sParam); }
- else {
- if (token[0].substring(0,1).equals(":")) {
- // Post Connect
- switch (nParam) {
- case -1:
- ProcessStringParam(sParam,token);
- break;
- case 1: // 001 - Welcome to IRC
- Got001 = true;
- Process001(nParam,token);
- break;
- case 4: // 004 - ISUPPORT
- case 5: // 005 - ISUPPORT
- Process004_005(nParam,token);
- break;
- case 332: // Topic on Join
- case 333: // Topic Setter On Join
- ProcessTopic(sParam,token);
- break;
- case 375: // MOTD Start
- break;
- case 353: // Names
- case 366: // End of Names
- ProcessNames(nParam,token);
- break;
- case 324: // Modes
- ProcessMode(sParam,token);
- case 329: // Channel Time
- case 368: // End of ban list
- break;
- case 376: // End of MOTD
- case 422: // No MOTD
- ProcessEndOfMOTD(nParam,token);
- break;
- case 433: // Nick In Use
- ProcessNickInUse(nParam,token);
- break;
- default: // Unknown
- break;
- }
- } else {
- // Pre Connect
- }
- }
- } catch (Exception e) { CallErrorInfo(errFatal,"Exception in Parser. {"+line+"} ["+e.getMessage()+"]"); e.getStackTrace(); }
- }
-
- private void ProcessStringParam(String sParam, String token[]) {
- // Process a line where the parameter is a string (IE PRIVMSG, NOTICE etc - Not including PING!)
- if (sParam.equalsIgnoreCase("PRIVMSG") || sParam.equalsIgnoreCase("NOTICE")) { ProcessIRCMessage(sParam,token); }
- else if (sParam.equalsIgnoreCase("JOIN")) { ProcessJoinChannel(sParam,token); }
- else if (sParam.equalsIgnoreCase("NICK")) { ProcessNickChange(sParam,token); }
- else if (sParam.equalsIgnoreCase("KICK")) { ProcessKickChannel(sParam,token); }
- else if (sParam.equalsIgnoreCase("PART")) { ProcessPartChannel(sParam,token); }
- else if (sParam.equalsIgnoreCase("QUIT")) { ProcessQuit(sParam,token); }
- else if (sParam.equalsIgnoreCase("TOPIC")) { ProcessTopic(sParam,token); }
- else if (sParam.equalsIgnoreCase("MODE")) { ProcessMode(sParam,token); }
- }
-
- private void ProcessNickChange(String sParam, String token[]) {
- ClientInfo iClient;
-
- iClient = GetClientInfo(token[0]);
- if (iClient != null) {
- if (iClient.getHost().equals("")) { iClient.setUserBits(token[0],false); }
- hClientList.remove(iClient.getNickname().toLowerCase());
- iClient.setUserBits(token[2],true);
- hClientList.put(iClient.getNickname().toLowerCase(),iClient);
- CallNickChanged(iClient, ClientInfo.ParseHost(token[0]));
- }
- }
-
- private void ProcessKickChannel(String sParam, String token[]) {
- ChannelClientInfo iChannelClient;
- ChannelClientInfo iChannelKicker;
- ChannelInfo iChannel;
- ClientInfo iClient;
- ClientInfo iKicker;
- String sReason = "";
-
- iClient = GetClientInfo(token[3]);
- iKicker = GetClientInfo(token[0]);
- iChannel = GetChannelInfo(token[2]);
-
- if (iClient == null) { return; }
- if (iChannel == null) {
- if (iClient != cMyself) {
- CallErrorInfo(errWarning+errCanContinue, "Got kick for channel ("+token[2]+") that I am not on. [User: "+token[3]+"]");
- }
- return;
- } else {
- if (token.length > 4) { sReason = token[token.length-1]; }
- iChannelClient = iChannel.getUser(iClient);
- iChannelKicker = iChannel.getUser(iClient);
- CallChannelKick(iChannel,iChannelClient,iChannelKicker,sReason,token[0]);
- iChannel.delClient(iClient);
- if (iClient == cMyself) {
- iChannel.emptyChannel();
- hChannelList.remove(iChannel.getName().toLowerCase());
- } else {
- if (!iClient.checkVisability()) {
- hClientList.remove(iClient.getNickname().toLowerCase());
- }
- }
- }
- }
-
- private void ProcessMode(String sParam, String token[]) {
- String[] sModestr;
- String sChannelName;
- String sModeParam;
- int nCurrent = 0, nParam = 1, nValue = 0;
- boolean bPositive = true, bBooleanMode = true;
- ChannelInfo iChannel;
- ChannelClientInfo iChannelClientInfo;
- ClientInfo iClient;
- if (sParam.equals("324")) {
- sChannelName = token[3];
- // Java 6 Only
- // sModestr = Arrays.copyOfRange(token,4,token.length);
- sModestr = new String[token.length-4];
- System.arraycopy(token, 4, sModestr, 0, token.length-4);
- } else {
- sChannelName = token[2];
- // Java 6 Only
- // sModestr = Arrays.copyOfRange(token,3,token.length);
- sModestr = new String[token.length-3];
- System.arraycopy(token, 3, sModestr, 0, token.length-3);
- }
-
- if (!ChannelInfo.isValidChannelName(this, sChannelName)) { ProcessUserMode(sParam, token, sModestr); return; }
-
- iChannel = GetChannelInfo(sChannelName);
- if (iChannel == null) {
- CallErrorInfo(errWarning+errCanContinue, "Got modes for channel ("+sChannelName+") that I am not on.");
- iChannel = new ChannelInfo(this, sChannelName);
- hChannelList.put(iChannel.getName().toLowerCase(),iChannel);
- }
- if (!sParam.equals("324")) { nCurrent = iChannel.getMode(); }
-
- for (int i = 0; i < sModestr[0].length(); ++i) {
- Character cMode = sModestr[0].charAt(i);
- if (cMode.equals("+".charAt(0))) { bPositive = true; }
- else if (cMode.equals("-".charAt(0))) { bPositive = false; }
- else if (cMode.equals(":".charAt(0))) { continue; }
- else {
- if (hChanModesBool.containsKey(cMode)) { nValue = hChanModesBool.get(cMode); bBooleanMode = true; }
- else if (hChanModesOther.containsKey(cMode)) { nValue = hChanModesOther.get(cMode); bBooleanMode = false; }
- else if (hPrefixModes.containsKey(cMode)) {
- // (de) OP/Voice someone
- sModeParam = sModestr[nParam++];
- nValue = hPrefixModes.get(cMode);
- if (bDebug) { System.out.printf("User Mode: %c [%s] {Positive: %b}\n",cMode, sModeParam, bPositive); }
- iChannelClientInfo = iChannel.getUser(sModeParam);
- if (iChannelClientInfo == null) {
- // Client not known?
- CallErrorInfo(errWarning+errCanContinue, "Got mode for client not known on channel - Added");
- iClient = GetClientInfo(sModeParam);
- if (iClient == null) {
- CallErrorInfo(errWarning+errCanContinue, "Got mode for client not known at all - Added");
- iClient = new ClientInfo(this, sModeParam);
- hClientList.put(iClient.getNickname().toLowerCase(),iClient);
- }
- iChannelClientInfo = iChannel.addClient(iClient);
- }
- if (bPositive) { iChannelClientInfo.setChanMode(iChannelClientInfo.getChanMode() + nValue); }
- else { iChannelClientInfo.setChanMode(iChannelClientInfo.getChanMode() - nValue); }
- continue;
- } else {
- CallErrorInfo(errWarning+errCanContinue, "Got unknown mode "+cMode+" - Added as boolean mode");
- hChanModesBool.put(cMode,nNextKeyCMBool);
- nValue = nNextKeyCMBool;
- bBooleanMode = true;
- nNextKeyCMBool = nNextKeyCMBool*2;
- }
-
- if (bBooleanMode) {
- if (bDebug) { System.out.printf("Boolean Mode: %c [%d] {Positive: %b}\n",cMode, nValue, bPositive); }
- if (bPositive) { nCurrent = nCurrent + nValue; }
- else { nCurrent = nCurrent - nValue; }
- } else {
- if (nValue == cmList) {
- sModeParam = sModestr[nParam++];
- iChannel.setListModeParam(cMode, sModeParam, bPositive);
- if (bDebug) { System.out.printf("List Mode: %c [%s] {Positive: %b}\n",cMode, sModeParam, bPositive); }
- } else {
- if (bPositive) {
- sModeParam = sModestr[nParam++];
- if (bDebug) { System.out.printf("Set Mode: %c [%s] {Positive: %b}\n",cMode, sModeParam, bPositive); }
- iChannel.setModeParam(cMode,sModeParam);
- } else {
- if ((nValue & cmUnset) == cmUnset) { sModeParam = sModestr[nParam++]; } else { sModeParam = ""; }
- if (bDebug) { System.out.printf("Unset Mode: %c [%s] {Positive: %b}\n",cMode, sModeParam, bPositive); }
- iChannel.setModeParam(cMode,"");
- }
- }
- }
- }
- }
-
- iChannel.setMode(nCurrent);
- if (sParam.equals("324")) { CallModesChanged(iChannel, null, ""); }
- else { CallModesChanged(iChannel, iChannel.getUser(token[0]), token[0]); }
- }
-
- // This isn't implemented yet.
- private void ProcessUserMode(String sParam, String token[], String sModestr[]) {
- int nCurrent = 0, nValue = 0;
- boolean bPositive = true;
-
- ClientInfo iClient;
-
- iClient = GetClientInfo(token[2]);
- if (iClient == null) { return; }
-
- nCurrent = iClient.getUserMode();
-
- for (int i = 0; i < sModestr[0].length(); ++i) {
- Character cMode = sModestr[0].charAt(i);
- if (cMode.equals("+".charAt(0))) { bPositive = true; }
- else if (cMode.equals("-".charAt(0))) { bPositive = false; }
- else if (cMode.equals(":".charAt(0))) { continue; }
- else {
- if (hUserModes.containsKey(cMode)) { nValue = hUserModes.get(cMode); }
- else {
- CallErrorInfo(errWarning+errCanContinue, "Got unknown user mode "+cMode+" - Added");
- hUserModes.put(cMode,nNextKeyUser);
- nValue = nNextKeyUser;
- nNextKeyUser = nNextKeyUser*2;
- }
-
- if (bDebug) { System.out.printf("User Mode: %c [%d] {Positive: %b}\n",cMode, nValue, bPositive); }
- if (bPositive) { nCurrent = nCurrent + nValue; }
- else { nCurrent = nCurrent - nValue; }
- }
- }
-
- iClient.setUserMode(nCurrent);
- CallUserModesChanged(iClient, token[0]);
- }
-
- private void ProcessNames(int nParam, String token[]) {
- ChannelInfo iChannel;
- if (nParam == 366) {
- // End of names
- iChannel = GetChannelInfo(token[2]);
- if (iChannel != null) {
- iChannel.bAddingNames = false;
- CallGotNames(iChannel);
- }
- } else {
- // Names
-
- ClientInfo iClient;
- ChannelClientInfo iChannelClient;
-
- iChannel = GetChannelInfo(token[4]);
-
- if (iChannel == null) {
- CallErrorInfo(errWarning+errCanContinue, "Got names for channel ("+token[4]+") that I am not on.");
- iChannel = new ChannelInfo(this, token[4]);
- hChannelList.put(iChannel.getName().toLowerCase(),iChannel);
- }
-
- // If we are not expecting names, clear the current known names - this is fresh stuff!
- if (!iChannel.bAddingNames) { iChannel.emptyChannel(); }
- iChannel.bAddingNames = true;
-
- String[] sNames = token[token.length-1].split(" ");
- String sNameBit = "", sModes = "", sName = "";
- int nPrefix = 0;
- for (int j = 0; j < sNames.length; ++j) {
- sNameBit = sNames[j];
- for (int i = 0; i < sNameBit.length(); ++i) {
- Character cMode = sNameBit.charAt(i);
- if (hPrefixMap.containsKey(cMode)) {
- sModes = sModes+cMode;
- nPrefix = nPrefix + hPrefixModes.get(hPrefixMap.get(cMode));
- } else {
- sName = sNameBit.substring(i);
- break;
- }
- }
- System.out.printf("Name: %s Modes: \"%s\" [%d]\n",sName,sModes,nPrefix);
-
- iClient = GetClientInfo(sName);
- if (iClient == null) { iClient = new ClientInfo(this, sName); hClientList.put(iClient.getNickname().toLowerCase(),iClient); }
- iChannelClient = iChannel.addClient(iClient);
- iChannelClient.setChanMode(nPrefix);
-
- sName = "";
- sModes = "";
- nPrefix = 0;
- }
- }
- }
-
- // This horrible thing handles PRIVMSGs and NOTICES
- // This inclues CTCPs and CTCPReplies
- // It handles all 3 targets (Channel, Private, Unknown)
- // Actions are handled here aswell separately from CTCPs.
- // Each type has 5 Calls, making 15 callbacks handled here.
- private void ProcessIRCMessage(String sParam, String token[]) {
- ChannelClientInfo iChannelClient = null;
- ChannelInfo iChannel = null;
- ClientInfo iClient = null;
- String sMessage = token[token.length-1];
- String[] bits = sMessage.split(" ", 2);
- Character Char1 = Character.valueOf((char)1);
- String sCTCP = "";
- boolean isAction = false;
- boolean isCTCP = false;
-
- iClient = GetClientInfo(token[0]);
-
- if (sParam.equalsIgnoreCase("PRIVMSG")) {
- if (bits[0].equalsIgnoreCase(Char1+"ACTION") && Character.valueOf(sMessage.charAt(sMessage.length()-1)).equals(Char1)) {
- isAction = true;
- } else if (Character.valueOf(sMessage.charAt(0)).equals(Char1) && Character.valueOf(sMessage.charAt(sMessage.length()-1)).equals(Char1)) {
- isCTCP = true;
- if (bits.length > 1) { sMessage = bits[1]; } else { sMessage = ""; }
- bits = bits[0].split(Char1.toString());
- sCTCP = bits[1];
- if (bDebug) { System.out.printf("CTCP: \"%s\" \"%s\"\n",sCTCP,sMessage); }
- }
- }
-
- if (ChannelInfo.isValidChannelName(this, token[2])) {
- iChannel = GetChannelInfo(token[2]);
- if (iClient != null && iChannel != null) { iChannelClient = iChannel.getUser(iClient); }
- if (sParam.equalsIgnoreCase("PRIVMSG")) {
- if (!isAction) {
- if (isCTCP) {
- CallChannelCTCP(iChannel, iChannelClient, sCTCP, sMessage, token[0]);
- } else {
- CallChannelMessage(iChannel, iChannelClient, sMessage, token[0]);
- }
- } else {
- CallChannelAction(iChannel, iChannelClient, sMessage, token[0]);
- }
- } else if (sParam.equalsIgnoreCase("NOTICE")) {
- if (isCTCP) {
- CallChannelCTCPReply(iChannel, iChannelClient, sCTCP, sMessage, token[0]);
- } else {
- CallChannelNotice(iChannel, iChannelClient, sMessage, token[0]);
- }
- }
- } else if (token[2].equalsIgnoreCase(cMyself.getNickname())) {
- if (sParam.equalsIgnoreCase("PRIVMSG")) {
- if (!isAction) {
- if (isCTCP) {
- CallPrivateCTCP(iClient, sCTCP, sMessage, token[0]);
- } else {
- CallPrivateMessage(iClient, sMessage, token[0]);
- }
- } else {
- CallPrivateAction(iClient, sMessage, token[0]);
- }
- } else if (sParam.equalsIgnoreCase("NOTICE")) {
- if (isCTCP) {
- CallPrivateCTCPReply(iClient, sCTCP, sMessage, token[0]);
- } else {
- CallPrivateNotice(iClient, sMessage, token[0]);
- }
- }
- } else {
- if (bDebug) { System.out.printf("Message for Other ("+token[2]+")\n"); }
- if (sParam.equalsIgnoreCase("PRIVMSG")) {
- if (!isAction) {
- if (isCTCP) {
- CallUnknownCTCP(iClient, sCTCP, sMessage, token[0]);
- } else {
- CallUnknownMessage(iClient, sMessage, token[0]);
- }
- } else {
- CallUnknownAction(iClient, sMessage, token[0]);
- }
- } else if (sParam.equalsIgnoreCase("NOTICE")) {
- if (isCTCP) {
- CallUnknownCTCPReply(iClient, sCTCP, sMessage, token[0]);
- } else {
- CallUnknownNotice(iClient, sMessage, token[0]);
- }
- }
- }
- }
-
- private void ProcessTopic(String sParam, String token[]) {
- ChannelInfo iChannel;
- if (sParam.equals("332")) {
- iChannel = GetChannelInfo(token[3]);
- if (iChannel == null) { return; };
- iChannel.setTopic(token[token.length-1]);
- } else if (sParam.equals("333")) {
- iChannel = GetChannelInfo(token[3]);
- if (iChannel == null) { return; };
- iChannel.setTopicTime(Long.parseLong(token[5]));
- iChannel.setTopicUser(token[5]);
- CallTopic(iChannel,false);
- } else {
- iChannel = GetChannelInfo(token[2]);
- if (iChannel == null) { return; };
- iChannel.setTopicTime(java.util.Calendar.getInstance().getTimeInMillis() / 1000);
- String sTemp[] = token[0].split(":",2);
- if (sTemp.length > 1) { token[0] = sTemp[1]; }
- iChannel.setTopicUser(token[0]);
- CallTopic(iChannel,true);
- }
- }
-
- private void ProcessJoinChannel(String sParam, String token[]) {
- // :nick!ident@host JOIN (:)#Channel
- Character cTemp;
- Byte nTemp;
- if (token.length < 3) { return; }
- ClientInfo iClient;
- ChannelInfo iChannel;
- ChannelClientInfo iChannelClient;
-
- iClient = GetClientInfo(token[0]);
- iChannel = GetChannelInfo(token[token.length-1]);
-
- if (iClient == null) { iClient = new ClientInfo(this, token[0]); hClientList.put(iClient.getNickname().toLowerCase(),iClient); }
- if (iChannel == null) {
- if (iClient != cMyself) {
- CallErrorInfo(errWarning+errCanContinue, "Got join for channel ("+token[token.length-1]+") that I am not on. [User: "+token[0]+"]");
- }
- iChannel = new ChannelInfo(this, token[token.length-1]);
- hChannelList.put(iChannel.getName().toLowerCase(),iChannel);
- SendString("MODE "+iChannel.getName());
-
- for (Enumeration e = hChanModesOther.keys(); e.hasMoreElements();) {
- cTemp = (Character)e.nextElement();
- nTemp = hChanModesOther.get(cTemp);
- if (nTemp == cmList) { SendString("MODE "+iChannel.getName()+" "+cTemp); }
- }
-
- } else {
- // This is only done if we are on the channel. Else we wait for names.
- iChannelClient = iChannel.addClient(iClient);
- CallChannelJoin(iChannel, iChannelClient);
- }
- }
-
- private void ProcessPartChannel(String sParam, String token[]) {
- // :nick!ident@host PART #Channel
- // :nick!ident@host PART #Channel :reason
- if (token.length < 3) { return; }
- ClientInfo iClient;
- ChannelInfo iChannel;
- ChannelClientInfo iChannelClient;
-
- iClient = GetClientInfo(token[0]);
- iChannel = GetChannelInfo(token[2]);
-
- if (iClient == null) { return; }
- if (iChannel == null) {
- if (iClient != cMyself) {
- CallErrorInfo(errWarning+errCanContinue, "Got part for channel ("+token[2]+") that I am not on. [User: "+token[0]+"]");
- }
- return;
- } else {
- String sReason = "";
- if (token.length > 3) { sReason = token[token.length-1]; }
- iChannelClient = iChannel.getUser(iClient);
- CallChannelPart(iChannel,iChannelClient,sReason);
- iChannel.delClient(iClient);
- if (iClient == cMyself) {
- iChannel.emptyChannel();
- hChannelList.remove(iChannel.getName().toLowerCase());
- } else { iClient.checkVisability(); }
- }
- }
-
- private void ProcessQuit(String sParam, String token[]) {
- // :nick!ident@host QUIT
- // :nick!ident@host QUIT :reason
- if (token.length < 2) { return; }
- ClientInfo iClient;
- ChannelInfo iChannel;
- ChannelClientInfo iChannelClient;
-
- iClient = GetClientInfo(token[0]);
-
- if (iClient == null) { return; }
-
- String sReason = "";
- if (token.length > 2) { sReason = token[token.length-1]; }
-
- for (Enumeration e = hChannelList.keys(); e.hasMoreElements();) {
- iChannel = hChannelList.get(e.nextElement());
- iChannelClient = iChannel.getUser(iClient);
- if (iChannelClient != null) {
- CallChannelQuit(iChannel,iChannelClient,sReason);
- if (iClient == cMyself) {
- iChannel.emptyChannel();
- hChannelList.remove(iChannel.getName().toLowerCase());
- } else {
- iChannel.delClient(iClient);
- }
- }
- }
-
- CallQuit(iClient,sReason);
- if (iClient == cMyself) {
- hClientList.clear();
- } else {
- hClientList.remove(iClient.getNickname().toLowerCase());
- }
- }
-
- private void Process004_005(int nParam, String token[]) {
- if (nParam == 4) {
- // 004
- h005Info.put("USERMODES",token[5]);
- } else {
- // 005
- String[] Bits = null;
- String sKey = null, sValue = null;
- for (int i = 3; i < token.length ; i++) {
- Bits = token[i].split("=",2);
- sKey = Bits[0].toUpperCase();
- if (Bits.length == 2) { sValue = Bits[1]; } else { sValue = ""; }
- if (bDebug) { System.out.printf("%s => %s \r\n",sKey,sValue); }
- h005Info.put(sKey,sValue);
- }
- }
- }
-
- protected void ParseChanModes() {
- final String sDefaultModes = "b,k,l,imnpstrc";
- String[] Bits = null;
- String ModeStr;
- if (h005Info.containsKey("CHANMODES")) { ModeStr = h005Info.get("CHANMODES"); }
- else { ModeStr = sDefaultModes; h005Info.put("CHANMODES",ModeStr); }
- Bits = ModeStr.split(",",4);
- if (Bits.length != 4) {
- ModeStr = sDefaultModes;
- CallErrorInfo(errError+errCanContinue, "CHANMODES String not valid. Using default string of \""+ModeStr+"\"");
- h005Info.put("CHANMODES",ModeStr);
- Bits = ModeStr.split(",",4);
- }
-
- // ResetState
- hChanModesOther.clear();
- hChanModesBool.clear();
- nNextKeyCMBool = 1;
-
- // List modes.
- for (int i = 0; i < Bits[0].length(); ++i) {
- Character cMode = Bits[0].charAt(i);
- if (bDebug) { System.out.printf("List Mode: %c\n",cMode); }
- if (!hChanModesOther.containsKey(cMode)) { hChanModesOther.put(cMode,cmList); }
- }
-
- // Param for Set and Unset.
- Byte nBoth = (cmSet+cmUnset);
- for (int i = 0; i < Bits[1].length(); ++i) {
- Character cMode = Bits[1].charAt(i);
- if (bDebug) { System.out.printf("Set/Unset Mode: %c\n",cMode); }
- if (!hChanModesOther.containsKey(cMode)) { hChanModesOther.put(cMode,nBoth); }
- }
-
- // Param just for Set
- for (int i = 0; i < Bits[2].length(); ++i) {
- Character cMode = Bits[2].charAt(i);
- if (bDebug) { System.out.printf("Set Only Mode: %c\n",cMode); }
- if (!hChanModesOther.containsKey(cMode)) { hChanModesOther.put(cMode,cmSet); }
- }
-
- // Boolean Mode
- for (int i = 0; i < Bits[3].length(); ++i) {
- Character cMode = Bits[3].charAt(i);
- if (bDebug) { System.out.printf("Boolean Mode: %c [%d]\n",cMode,nNextKeyCMBool); }
- if (!hChanModesBool.containsKey(cMode)) {
- hChanModesBool.put(cMode,nNextKeyCMBool);
- nNextKeyCMBool = nNextKeyCMBool*2;
- }
- }
- }
-
- protected void ParseUserModes() {
- final String sDefaultModes = "nwdoi";
- String[] Bits = null;
- String ModeStr;
- if (h005Info.containsKey("USERMODES")) { ModeStr = h005Info.get("USERMODES"); }
- else { ModeStr = sDefaultModes; h005Info.put("USERMODES", sDefaultModes); }
-
- // ResetState
- hUserModes.clear();
- nNextKeyUser = 1;
-
- // Boolean Mode
- for (int i = 0; i < ModeStr.length(); ++i) {
- Character cMode = ModeStr.charAt(i);
- if (bDebug) { System.out.printf("User Mode: %c [%d]\n",cMode,nNextKeyUser); }
- if (!hUserModes.containsKey(cMode)) {
- hUserModes.put(cMode,nNextKeyUser);
- nNextKeyUser = nNextKeyUser*2;
- }
- }
- }
-
- protected void ParseChanPrefix() {
- final String sDefaultModes = "#&";
- String[] Bits = null;
- String ModeStr;
- if (h005Info.containsKey("CHANTYPES")) { ModeStr = h005Info.get("CHANTYPES"); }
- else { ModeStr = sDefaultModes; h005Info.put("CHANTYPES", sDefaultModes); }
-
- // ResetState
- hChanPrefix.clear();
-
- // Boolean Mode
- for (int i = 0; i < ModeStr.length(); ++i) {
- Character cMode = ModeStr.charAt(i);
- if (bDebug) { System.out.printf("Chan Prefix: %c\n",cMode); }
- if (!hChanPrefix.containsKey(cMode)) { hChanPrefix.put(cMode,true); }
- }
- }
-
- protected void ParsePrefixModes() {
- final String sDefaultModes = "(ohv)@%+";
- String[] Bits = null;
- String ModeStr;
- if (h005Info.containsKey("PREFIX")) { ModeStr = h005Info.get("PREFIX"); }
- else { ModeStr = sDefaultModes; }
- if (ModeStr.substring(0,1).equals("(")) { ModeStr = ModeStr.substring(1); }
- else { ModeStr = sDefaultModes.substring(1); h005Info.put("PREFIX", sDefaultModes); }
-
- Bits = ModeStr.split("\\)",2);
- if (Bits.length != 2 || Bits[0].length() != Bits[1].length()) {
- ModeStr = sDefaultModes;
- CallErrorInfo(errError+errCanContinue, "PREFIX String not valid. Using default string of \""+ModeStr+"\"");
- h005Info.put("PREFIX",ModeStr);
- ModeStr = ModeStr.substring(1);
- Bits = ModeStr.split("\\)",2);
- }
-
- // ResetState
- hPrefixModes.clear();
- hPrefixMap.clear();
- nNextKeyPrefix = 1;
-
- for (int i = 0; i < Bits[0].length(); ++i) {
- Character cMode = Bits[0].charAt(i);
- Character cPrefix = Bits[1].charAt(i);
- if (bDebug) { System.out.printf("Prefix Mode: %c => %c [%d]\n",cMode,cPrefix,nNextKeyPrefix); }
- if (!hPrefixModes.containsKey(cMode)) {
- hPrefixModes.put(cMode,nNextKeyPrefix);
- hPrefixMap.put(cMode,cPrefix);
- hPrefixMap.put(cPrefix,cMode);
- nNextKeyPrefix = nNextKeyPrefix*2;
- }
- }
-
- }
-
- private void ProcessEndOfMOTD(int nParam, String token[]) {
- ParseChanModes();
- ParseChanPrefix();
- ParsePrefixModes();
- ParseUserModes();
- CallMOTDEnd();
- }
-
- private void Process001(int nParam, String token[]) {
- // << :demon1.uk.quakenet.org 001 Java-Test :Welcome to the QuakeNet IRC Network, Java-Test
- String sNick;
- sServerName = token[0].substring(1,token[0].length());
- sNick = token[2];
- /* Code below is here incase relying on token[2] breaks somewhere
- String[] temp = token[token.length-1].split(" ");
- sConfirmedNickname = temp[temp.length-1];
- // Some servers give a full host in 001
- temp = sNick.split("!",2);
- sNick = temp[0]; /* */
-
- cMyself = GetClientInfo(sNick);
- if (cMyself == null) { cMyself = new ClientInfo(this, sNick); }
- }
-
- private void ProcessNickInUse(int nParam, String token[]) {
- if (!CallNickInUse()) {
- // Manually handle nick in use.
- CallDebugInfo(ndInfo,"No Nick in use Handler.");
- if (!Got001) {
- CallDebugInfo(ndInfo,"Using inbuilt handler");
- // If this is before 001 we will try and get a nickname, else we will leave the nick as-is
- if (!TriedAlt) { SetNickname(me.sAltNickname); TriedAlt = true; }
- else {
- if (sThinkNickname.equalsIgnoreCase(me.sAltNickname)) { sThinkNickname = me.sNickname; }
- SetNickname('_'+sThinkNickname);
- }
- }
- }
- }
-
-
- /**
- * Join a Channel.
- *
- * @param sChannelName Name of channel to join
- */
- public void JoinChannel(String sChannelName) {
- if (!ChannelInfo.isValidChannelName(this,sChannelName)) { return; }
- SendString("JOIN "+sChannelName);
- }
-
-
- /**
- * Leave a Channel.
- *
- * @param sChannelName Name of channel to join
- */
- public void PartChannel(String sChannelName, String sReason) {
- if (!ChannelInfo.isValidChannelName(this,sChannelName)) { return; }
- if (sReason.equals("")) { SendString("PART "+sChannelName); }
- else { SendString("PART "+sChannelName+" :"+sReason); }
- }
-
- /**
- * Set Nickname.
- *
- * @param sNewNickName New nickname wanted.
- */
- public void SetNickname(String sNewNickName) {
- sThinkNickname = sNewNickName;
- SendString("NICK "+sNewNickName);
- }
-
- /**
- * Quit server. This method will wait for the server to close the socket.
- *
- * @param sReason Reason for quitting.
- */
- public void Quit(String sReason) {
- if (sReason.equals("")) { SendString("QUIT"); }
- else { SendString("QUIT :"+sReason); }
- }
- /**
- * Disconnect from server. This method will quit and automatically close the
- * socket without waiting for the server
- *
- * @param sReason Reason for quitting.
- */
- public void Disconnect(String sReason) {
- Quit(sReason);
- try { socket.close(); } catch (Exception e) { /* Meh */ };
- }
-
- /**
- * Get SVN Version information
- *
- * @return SVN Version String
- */
- public static String getSvnInfo () { return "$Id$"; }
- }
-
- // eof
|