Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class mixed extends irccallback {
- var $helpMessageLock=array();
- var $statusMessageLock=array();
- function statusUnlock($data) {
- $this->statusMessageLock[$data['unlockThis']]=false;
- }
- function helpUnlock($data) {
- $this->helpMessageLock[$data['unlockThis']]=false;
- }
- function mixedPrivateMessage($data) {
- global $db;
- $owner = $this->irc->getNick($data[0]);
- //$this->irc->messageTo($this->channel, 'I got the message!');
- switch ($data[3]) {
- case ':!start':
- // date time avail isok
- $BOOL_CHECK = array(false, false, false, false);
- // if(count($data)==4) {
- if(count($data)>=4) {
- if(isset($data[4])) {
- $players=(int)$data[4];
- if($players<12) $players=12;
- if($players>20) $players=20;
- }
- else {
- $players=$this->irc->cfg['max_players'];
- }
- $timestamp=-1;
- $uref=base_convert(time(),10,16);
- $q=$db->getBuilder();
- $q->add('id');
- $q->where('timestamp', $timestamp);
- $q->whereString('channel', $this->channel);
- $q->where('active', true);
- $q->goSelect('bot_match');
- $db->execute($q);
- $query=$db->makeArray();
- if(count($query)==0) {
- $BOOL_CHECK[0]=true;
- $BOOL_CHECK[1]=true;
- $BOOL_CHECK[2]=true;
- }
- else {
- $this->irc->messageTo($this->channel, 'Mixed match already setup.');
- }
- }
- if($BOOL_CHECK[0] && $BOOL_CHECK[1] && $BOOL_CHECK[2]) {
- $BOOL_CHECK[3]=true;
- }
- if($BOOL_CHECK[3]) {
- $q=$db->getBuilder();
- $q->addString('reference', $uref);
- $q->addString('owner', $owner);
- $q->add('timestamp', $timestamp);
- $q->add('max_players', $players);
- $q->addString('channel', $this->channel);
- $q->add('active', true);
- $q->goInsert('bot_match');
- $db->execute($q);
- $this->irc->messageTo($this->channel, 'Mixed created for '.$players.' players. Starting when full.');
- }
- //$this->callbackTOPIC($data);
- break;
- case ':!finish':
- if(count($data)==4) {
- $timestamp=-1;
- $q=$db->getBuilder();
- $q->add('id');
- $q->add('owner');
- $q->where('timestamp', $timestamp);
- $q->whereString('channel', $this->channel);
- $q->where('active', 1);
- $q->goSelect('bot_match');
- $db->execute($q);
- $query=$db->makeArray();
- $this->debug($query['id']);
- if(count($query)>0) {
- $this->debug('REQUEST Finish By: '.$owner);
- $validOwner = false;
- $validOwner |= $this->irc->isOp($this->channel, $owner);
- $validOwner |= ($query[0]['owner']==$owner)?true:false;
- if($validOwner) {
- $q=$db->getBuilder();
- $q->add('timestamp', time());
- $q->add('active', 0);
- $q->where('id', $query[0]['id']);
- $q->goUpdate('bot_match');
- $db->execute($q);
- $this->irc->messageTo($this->channel, 'Mixed finished.');
- }
- }
- else {
- $this->irc->messageTo($this->channel, 'No unfinished Mixed found.');
- }
- }
- break;
- case ':!debug': {
- }
- case ':!add':
- if(count($data)==4) {
- $timestamp=-1;
- $q=$db->getBuilder();
- $q->add('reference');
- $q->add('max_players');
- $q->where('timestamp', $timestamp);
- $q->whereString('channel', $this->channel);
- $q->where('active', 1);
- $q->goSelect('bot_match');
- $db->execute($q);
- $query=$db->makeArray();
- //Valid Match?
- if(count($query)>0) {
- $max_players = $query[0]['max_players'];
- $max_subs = $this->irc->cfg['max_subs'];
- $this->debug('NICKNAME: '.$owner);
- $q=$db->getBuilder();
- $q->add('id');
- $q->whereString('name', $owner);
- $q->whereString('reference', $query[0]['reference']);
- $q->goSelect('bot_players');
- $db->execute($q);
- $this->debug('>> CURRENT SQL COUNT [Is player already in]: '. $db->count());
- if($db->count()!=false) {
- $this->irc->messageTo($this->channel, 'You are already signed to the mix. Dont be a t00l');
- break;
- }
- // Get Enrolled Player count
- $q=$db->getBuilder();
- $q->add('id');
- $q->whereString('reference', $query[0]['reference']);
- $q->where('isSub', 0);
- $q->goSelect('bot_players');
- $db->execute($q);
- $cur_count = $db->count();
- // Get Enrolled Player count
- $q=$db->getBuilder();
- $q->add('id');
- $q->whereString('reference', $query[0]['reference']);
- $q->where('isSub', 1);
- $q->goSelect('bot_players');
- $db->execute($q);
- $sub_count = $db->count();
- if($cur_count<$max_players) {
- //Add to team
- $q=$db->getBuilder();
- $q->addString('name', $owner);
- $q->addString('reference', $query[0]['reference']);
- $q->add('isSub', 0);
- $q->add('timestamp',time());
- $q->goInsert('bot_players');
- $db->execute($q);
- $this->irc->messageTo($this->channel, 'Congratulations '.$owner.' you have been added to the mixed. Players: ['.($cur_count+1).'/'.$max_players.'][SUB: '.$sub_count.'/'.$max_subs.']');
- } else {
- //Can I add to sub? if so, add to sub list...
- if($sub_count<$max_subs) {
- $q=$db->getBuilder();
- $q->addString('name', $owner);
- $q->addString('reference', $query[0]['reference']);
- $q->add('isSub', 1);
- $q->add('timestamp',time());
- $q->goInsert('bot_players');
- $db->execute($q);
- $this->irc->messageTo($this->channel, 'Congratulations '.$owner.' you have been added to the reserves for the mixed. Players: ['.$cur_count.'/'.$max_players.'][SUB: '.($sub_count+1).'/'.$max_subs.']');
- } else {
- //Sorry, its full!
- $this->irc->messageTo($this->channel, 'Im sorry '.$owner.' this mixed is full. Im sure another will be setup up again soon. Players: ['.$max_players.'/'.$max_players.'][SUB: '.$max_subs.'/'.$max_subs.']');
- }
- }
- }
- else {
- $this->irc->messageTo($this->channel, 'No mixed currently active.');
- }
- }
- break;
- case ':!del':
- if(count($data)==4) {
- $timestamp=-1;
- $q=$db->getBuilder();
- $q->add('reference');
- $q->add('max_players');
- $q->whereString('channel', $this->channel);
- $q->where('timestamp', $timestamp);
- $q->where('active', 1);
- $q->goSelect('bot_match');
- $db->execute($q);
- $query=$db->makeArray();
- if(count($query)>0) {
- $max_players = $query[0]['max_players'];
- $max_subs = $this->irc->cfg['max_subs'];
- //Get count...
- //Get Enrolled Player count
- $q=$db->getBuilder();
- $q->add('id');
- $q->whereString('reference', $query[0]['reference']);
- $q->where('isSub', 0);
- $q->goSelect('bot_players');
- $db->execute($q);
- $cur_count = $db->count();
- // Get Enrolled Player count
- $q=$db->getBuilder();
- $q->add('id');
- $q->whereString('reference', $query[0]['reference']);
- $q->where('isSub', 1);
- $q->goSelect('bot_players');
- $db->execute($q);
- $sub_count = $db->count();
- //Find me!
- $q=$db->getBuilder();
- $q->whereString('reference', $query[0]['reference']);
- $q->whereString('name', $owner);
- $q->limit(1);
- $q->goSelect('bot_players');
- $db->execute($q);
- //Player in the mix?
- if($db->count()==0) {
- $this->irc->messageTo($this->channel, 'You are currently not signed to the mix.');
- break;
- }
- else {
- $wasSub = $db->direct('isSub');
- $wasPlayerID = $db->direct('id');
- //remove this player
- $q=$db->getBuilder();
- $q->where('id', $wasPlayerID);
- $q->goDelete('bot_players');
- $q->limit(1);
- $db->execute($q);
- $this->irc->messageTo($this->channel, ' Brave brave Sir '.$owner.' you have been successfully removed from the mixed.');
- //Was this player part of the main list? If so, can we upgrade a sub?
- if($wasSub==0) {
- $q=$db->getBuilder();
- $q->add('id');
- $q->add('name');
- $q->whereString('reference', $query[0]['reference']);
- $q->where('isSub',1);
- $q->sort('timestamp', 'ASC');
- $q->limit(1);
- $q->goSelect('bot_players');
- $db->execute($q);
- if($db->count()>0) {
- $theSub = $db->data(0);
- $this->irc->messageTo($this->channel, 'Congratulations '.$theSub['name'].' you have been moved from \'SUBS\'. Players: ['.($cur_count).'/'.$max_players.'][SUB: '.($sub_count-1).'/'.$max_subs.']');
- $q=$db->getBuilder();
- $q->add('isSub',0);
- $q->whereString('id', $theSub['id']);
- $q->goUpdate('bot_players');
- $db->execute($q);
- }
- }
- }
- }
- else {
- $this->irc->messageTo($this->channel, 'No mixed currently active.');
- }
- }
- break;
- case ':!status':
- $final_message=array();
- $this->debug('>>PRIVMSG [Command found= '.$data[3].']');
- $outputTo = $owner;
- if(isset($data[4])) {
- if(strcmp('p', $data[4])==0) {
- $outputTo = $this->channel;
- }
- }
- if(!isset($this->statusMessageLock[$outputTo])) $this->statusMessageLock[$outputTo]=false;
- if($this->statusMessageLock[$outputTo]===false) {
- if(count($data)>=4) {
- $this->statusMessageLock[$outputTo]=true;
- $timestamp=-1;
- $q=$db->getBuilder();
- $q->add('reference');
- $q->add('max_players');
- $q->whereString('channel', $this->channel);
- $q->where('timestamp', $timestamp);
- $q->where('active', 1);
- $q->goSelect('bot_match');
- $db->execute($q);
- $query=$db->makeArray();
- if($db->count()>0) {
- $q=$db->getBuilder();
- $q->add('name');
- $q->add('isSub');
- $q->whereString('reference', $query[0]['reference']);
- $q->sort('id','ASC');
- $q->goSelect('bot_players');
- $db->execute($q);
- $query2 = $db->makeArray();
- if($db->count()>0) {
- $player_count=0;
- $sub_count=0;
- $msg='';
- $temp=array();
- foreach($query2 as $p) {
- if($p['isSub']==0) {
- $temp[] = $p['name'];
- $player_count+=1;
- }
- }
- $msg=implode(', ', $temp);
- $this->irc->messageTo($outputTo, 'Players ['.$player_count.'/'.$query[0]['max_players'].']: '.$msg, 1.5);
- $msg='';
- $temp=array();
- foreach($query2 as $p) {
- if($p['isSub']==1) {
- $temp[] = $p['name'];
- $sub_count+=1;
- }
- }
- $msg=implode(', ', $temp);
- $last = $this->irc->messageTo($outputTo, 'Subs ['.$sub_count.'/'.$this->irc->cfg['max_subs'].']: '.$msg, 1.5);
- }
- else {
- $last = $this->irc->messageTo($outputTo, 'No signed players to current mixed.');
- }
- }
- else {
- $last = $this->irc->messageTo($outputTo, 'No mixed currently active.');
- }
- }
- $this->irc->office->dispatch($last + 4, $this, 'statusUnlock', '',array('unlockThis'=>$outputTo));
- }
- break;
- case ':!help':
- $outputTo = $owner;
- if(isset($data[4])) {
- if(strcmp('p', $data[4])==0) {
- $outputTo = $this->channel;
- }
- }
- if(!isset($this->statusMessageLock[$outputTo])) $this->statusMessageLock[$outputTo]=false;
- if($this->statusMessageLock[$outputTo]===false) {
- $this->helpMessageLock[$outputTo]=true;
- $hlpstr = array(
- '!start [x] - Start a mixed. Default is 16, you can optionally specify player count',
- '!finish - Cancel/Finish a mixed.',
- '!add - sign up for a game.',
- '!del - remove from a game.',
- '!status [p]- show status of mixed, p = channel message',
- '!help [p]- Your looking at it!, p = channel message',
- // '!schedule {date} - show a list of available mixed. if {date} is set displays for entered date.',
- // '!signed <id> - shows a list of signed up players for a specified mixed'
- );
- //$delay=0;
- foreach($hlpstr as $message) {
- $last = $this->irc->messageTo($outputTo, $message, 1.2);
- }
- $this->irc->office->dispatch($last+1, $this, 'helpUnlock', '' ,array('unlockThis'=>$outputTo));
- }
- break;
- }
- }
- function adminDeletePlayer($data) {
- if(!$this->irc->isOp($this->channel,$data['who'])) return;
- $pass=array();
- $pass[0]=$data['toDelete'];
- $pass[1]='something';
- $pass[2]='channel';
- $pass[3]=':!del';
- $this->mixedPrivateMessage($pass);
- }
- function function2($data) {
- $this->irc->messageTo($data['who'],' You just added yourself to the ' . $this->channel . ' mixed!');
- }
- function onInit() {
- $this->registerCallback('PRIVMSG', 'mixedPrivateMessage');
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment