// Last Update : 10:20AM 19/11/2012 // Credits to AnnieRuru // ==== TO-DO ==== // - NPC Dialog Lists // - Add Block User Features ? // - Clean the Scripts ..... - script IRC -1,{ function IRC_Create; function IRC_Join; function IRC_Broadcast; function IRC_Add; function IRC_Remove; function IRC_List; function IRC_getSlot; OnInit: // Max IRC Room .MaxRoom = 10; // Max Users in IRC .MaxUser = 100; // Display Time .DisplayTime = 1; // Kick when idle X Seconds .IdleKick = 600; // IRC Message Colour .CHAT$ = "0xFFBBFF"; .SYSTEM$ = "0x00EE55"; // IRC Commands .irc_create$ = "create"; .irc_join$ = "join"; .irc_leave$ = "leave"; .irc_list$ = "list"; .irc_kick$ = "kick"; .irc_invite$ = "invite"; // .irc_help$ = "help"; .irc_reject$ = "reject"; // IRC Messages ( will add on future ) // .message$[0] = "IRC Room reach limit."; // .message$[1] = "Please leave your current IRC Room."; // .message$[2] = "Didnt have any available IRC Room."; // .message$[3] = "You didnt join any IRC Room"; // Delete Data during Test Mode for ( .@i = 2000000; .@i < 2000003; .@i++ ) if ( attachrid(.@i) ) set @IRC, 0; end; OnWhisperGlobal: .@OriginalUser$ = strcharinfo(0); if( @whispervar0$ == .irc_create$ ){ if( getarraysize( .IRC_Room$ ) >= .MaxRoom ){ dispbottom "Max IRC Room Reach."; }else if( @IRC ){ dispbottom "Please leave your current IRC Room"; }else if( getstrlen(@whispervar1$) < 4 || getstrlen(@whispervar1$) > 24 ){ dispbottom "Usage : create#irc_name#irc_password ( if any password )"; dispbottom "irc_name must be between 4 ~ 24"; }else if( getstrlen( @whispervar2$ ) && getstrlen( @whispervar2$ ) < 4 ){ dispbottom "If you gonna add Password for IRC Room, the Password must not less than 4 characters."; }else{ @IRC = IRC_Create( @whispervar1$,@whispervar2$ ); if( @IRC ){ dispbottom "Successfully create a Room."; IRC_Add( ( @IRC - 1 ),strcharinfo(0) ); @Slot = 0; setd( ".IRC_Idle_"+@IRC+"["+@Slot+"]" ),0; deltimer strnpcinfo(0)+"::OnIdleCheck"; addtimer 1000,strnpcinfo(0)+"::OnIdleCheck"; // Clear variable ... @whispervar1$ = ""; @whispervar2$ = ""; }else{ dispbottom "Failed to create a Room."; } } }else if( @whispervar0$ == .irc_join$ ){ if( getarraysize( .IRC_Room$ ) <= 0 ){ dispbottom "Didnt have any available IRC Room."; }else if( @IRC ){ dispbottom "Please leave your current IRC Room"; }else{ @IRC = IRC_Join(); IRC_Add( ( @IRC - 1 ),strcharinfo(0) ); @Slot = IRC_getSlot( ( @IRC - 1 ),strcharinfo(0) ); setd( ".IRC_Idle_"+@IRC+"["+@Slot+"]" ),0; deltimer strnpcinfo(0)+"::OnIdleCheck"; addtimer 1000,strnpcinfo(0)+"::OnIdleCheck"; } }else if( @whispervar0$ == .irc_leave$ ){ if( !@IRC ){ dispbottom "You didnt join any IRC Room."; }else{ @Slot = IRC_getSlot( ( @IRC - 1 ),strcharinfo(0) ); IRC_Remove( ( @IRC - 1 ),strcharinfo(0),@Slot ); setd( ".IRC_Idle_"+@IRC+"["+@Slot+"]" ),0; @IRC = 0; dispbottom "You have left the IRC Channel"; deltimer strnpcinfo(0)+"::OnIdleCheck"; } }else if( @whispervar0$ == .irc_list$ ){ if( !@IRC ){ dispbottom "You didnt join any IRC Room."; }else{ IRC_List( ( @IRC - 1 ),strcharinfo(0) ); } }else if( @whispervar0$ == .irc_kick$ ){ if( getd( ".IRC_Room_"+( @IRC - 1 )+"$[0]" ) != strcharinfo(0) ){ dispbottom "Only a MOD of a channel can use this to kick player in this Channel."; }else{ .@ExpelName$ = @whispervar1$; if( attachrid( getcharid(3,.@ExpelName$) ) ){ @Slot = IRC_getSlot( ( @IRC - 1 ),.@ExpelName$ ); IRC_Remove( ( @IRC - 1 ),.@ExpelName$ ); dispbottom "You have been kicked out from the IRC by MOD"; deltimer strnpcinfo(0)+"::OnIdleCheck"; setd( ".IRC_Idle_"+( @IRC - 1 )+"["+@Slot+"]" ),0; @IRC = 0; } attachrid( getcharid( 3,.@OriginalUser$ ) ); } }else if( @whispervar0$ == .irc_reject$ ){ @AutoReject = !@AutoReject; dispbottom ( ( @AutoReject )?"Auto Reject":"Enable" )+" Invitation from other IRC Channel"; }else if( @whispervar0$ == .irc_invite$ ){ if( getd( ".IRC_Room_"+( @IRC - 1 )+"$[0]" ) != strcharinfo(0) ){ dispbottom "Only a MOD of a channel can invite another player into this Channel."; }else{ .@Channel = @IRC; .@Name$ = @whispervar1$; if( attachrid( getcharid(3,.@Name$) ) ){ if( @AutoReject || @IRC ){ .@i = 0; if( @AutoReject ) dispbottom "Rejected IRC Invitation from "+.@OriginalUser$+"."; }else{ .@i = @Slot = IRC_Add( ( .@Channel - 1 ),.@Name$ ); addtimer 1000,strnpcinfo(0)+"::OnIdleCheck"; if( @Slot >= 0 ) @IRC = .@Channel; } } attachrid( getcharid( 3,.@OriginalUser$ ) ); if( .@i < 0 ) dispbottom "Failed to add this Player into this Channel."; } }else if( @IRC <= 0 ){ dispbottom "You didnt join any IRC Room."; dispbottom "To Create a Channel : type 'create#irc_name#irc_password' ( if any )"; dispbottom "To Join a Channel : type 'join'"; }else{ @Slot = IRC_getSlot( ( @IRC - 1 ),strcharinfo(0) ); set .@MSG$, strcharinfo(0) +" : "+ @whispervar0$; IRC_Broadcast( ( @IRC - 1 ),.@MSG$,.CHAT$,strcharinfo(0) ); setd( ".IRC_Idle_"+( @IRC - 1 )+"["+@Slot+"]" ),0; deltimer strnpcinfo(0)+"::OnIdleCheck"; addtimer 1000,strnpcinfo(0)+"::OnIdleCheck"; } close; OnIdleCheck: @Slot = IRC_getSlot( ( @IRC - 1 ),strcharinfo(0) ); setd( ".IRC_Idle_"+( @IRC - 1 )+"["+@Slot+"]" ),( getd( ".IRC_Idle_"+( @IRC - 1 )+"["+@Slot+"]" ) + 1 ); if( getd( ".IRC_Idle_"+( @IRC - 1 )+"["+@Slot+"]" ) >= .IdleKick ){ setd( ".IRC_Idle_"+( @IRC - 1 )+"["+@Slot+"]" ),0; IRC_Remove( ( @IRC - 1 ),strcharinfo(0) ); @IRC = 0; dispbottom "You have keen auto-kicked out from the IRC Channel due to Idled so long."; }else if( @IRC ) addtimer 1000,strnpcinfo(0)+"::OnIdleCheck"; end; OnPCLogoutEvent: if( @IRC ) IRC_Remove( ( @IRC - 1 ),strcharinfo(0) ); end; // getarg(0) = Room // getarg(1) = Player Name function IRC_Add { .@size = getarraysize( getd( ".IRC_Room_"+getarg(0)+"$" ) ); for( .@i = 0; .@i < .@size; .@i++ ) if( getd( ".IRC_Room_"+getarg(0)+"$["+.@i+"]" ) == getarg(1) ) return -1; setd( ".IRC_Room_"+getarg(0)+"$["+.@size+"]" ),getarg(1); IRC_Broadcast( getarg(0),"( IRC ) : '"+getarg(1)+"' joined this room",.SYSTEM$,getarg(1) ); return .@size; } // getarg(0) = Room // getarg(1) = Player Name function IRC_Remove { .@Slot = IRC_getSlot( getarg(0),getarg(1) ); if( .@Slot >= 0 ){ IRC_Broadcast( getarg(0),"( IRC ) : '"+getarg(1)+"' left this room",.SYSTEM$,getarg(1) ); deletearray getd( ".IRC_Room_"+getarg(0)+"$["+.@Slot+"]" ),1; } // Delete Room & Password from Room Lists if empty users if( getarraysize( getd( ".IRC_Room_"+getarg(0)+"$" ) ) <= 0 ){ .IRC_Room$[ getarg(0) ] = ""; .IRC_Pass$[ getarg(0) ] = ""; } return attachrid( getcharid(3,getarg(1) ) ); } // getarg(0) = Room function IRC_List { dispbottom "========= IRC INFORMATION =========="; dispbottom "IRC Name : "+.IRC_Room$[ getarg(0) ]; dispbottom "IRC Type : "+( ( getstrlen( .IRC_Pass$[ getarg(0) ] ) )?"Secured ( '"+.IRC_Pass$[ getarg(0) ]+"' )":"Public" ); dispbottom "========= IRC USER LIST ==========="; .@size = getarraysize( getd( ".IRC_Room_"+getarg(0)+"$" ) ); for( .@i = 0; .@i < .@size; .@i++ ) dispbottom " -> "+getd( ".IRC_Room_"+getarg(0)+"$["+.@i+"]" )+" Idled : "+getd( ".IRC_Idle_"+getarg(0)+"["+.@i+"]" )+" seconds"+ ( ( .@i == 0 )?" [ MOD ]":"" ); dispbottom "========= IRC USER LIST ==========="; dispbottom "Total User : "+.@size; return; } // getarg(0) = Room // getarg(1) = Message // getarg(2) = Color // getarg(3) = Attach Target Player function IRC_Broadcast { freeloop(1); for( .@i = 0; .@i < getarraysize( getd( ".IRC_Room_"+getarg(0)+"$" ) ); .@i++ ) if( attachrid( getcharid( 3,getd( ".IRC_Room_"+getarg(0)+"$["+.@i+"]" ) ) ) ){ announce ( ( .DisplayTime )?"[ "+gettimestr("%H:%M",7)+" ] ":"" ) + getarg(1),bc_self,getarg(2); } freeloop(0); return attachrid( getcharid( 3,getarg(3) ) ); } // getarg(0) = Room Title // getarg(1) = Room Password if any function IRC_Create { for( .@i = 0; .@i < .MaxRoom; .@i++ ) if( .IRC_Room$[.@i] == "" ){ .IRC_Room$[.@i] = getarg(0); .IRC_Pass$[.@i] = getarg(1); return ( .@i + 1 ); } return 0; } // List Channel and Select function IRC_Join { for( .@i = 0; .@i < getarraysize( .IRC_Room$ ); .@i++ ) set .@Menu$,.@Menu$ + ( ( .IRC_Room$[.@i] == "" )?"":"^FF0000[ "+( ( getstrlen( .IRC_Pass$[.@i] ) >= 4 )?"S":"P" )+" ] ^0055FF"+.IRC_Room$[.@i]+" ^FF0000( "+getarraysize( getd( ".IRC_Room_"+.@i+"$") )+" / "+.MaxUser+" Users )^000000" ) +":"; do{ mes "^0055FF[ S ]^000000 = ^777777Secured Room^000000"; mes "^0055FF[ P ]^000000 = ^777777Public Room^000000"; .@Room = select( .@Menu$ ); if( getstrlen( .IRC_Pass$[(.@Room - 1)] ) >= 4 ){ mes "Please enter the IRC Password."; input .@Pass$; if( .@Pass$ != .IRC_Pass$[(.@Room - 1)] ){ mes "^FF0000Invalid Password^000000"; next; } } }while( getstrlen( .IRC_Pass$[(.@Room - 1)] ) >= 4 && .@Pass$ != .IRC_Pass$[(.@Room - 1)] ); return .@Room; } // getarg(0) = IRC Channel // getarg(1) = Player Name function IRC_getSlot { .@size = getarraysize( getd( ".IRC_Room_"+getarg(0)+"$" ) ); for( .@i = 0; .@i < .@size; .@i++ ) if( getd( ".IRC_Room_"+getarg(0)+"$["+.@i+"]" ) == getarg(1) ) return .@i; return -1; } }