All pastes #482492 Raw Edit

w_lookup.php

public php v1 · immutable
·published 2007-05-11 09:04 UTC
rendered paste body
<?php/** Online Status Web Module for BeBot <http://bebot.shadow-realm.org/>* Module coded by Craized <http://www.craized.net >/*Add a "_" at the beginning of the file (w_lookup.php) if you do not want it to be loaded.*/$w_lookup = new Status($bot);$cron["2sec"][] = &$w_lookup;$commands['buddy'][] = &$w_lookup;/*The Class itself...*/class Status {	var $bot;	/*	Constructor:	Hands over a referance to the "Bot" class.	*/	function Status (&$bot) {		$this -> bot = &$bot;	}	function cron() {		// Make our players available to all functions		global $players;		// Select our watch list		$handle = mysql_query("SELECT * FROM w_lookup");		while(TRUE == ($players = mysql_fetch_array$handle))		if(!empty($players)) {			// Loop through users and check their status			foreach($players as $key=>$value) {				// Format name to match AO internal				$value['name'] = ucfirst(strtolower($value['name']));				// Make sure it's not time to delete our cached entry				if($value['expire'] > mktime()) {					// If player status is unknown we find out what it is					if($value == 3) {						// Check if player name exists						if($this -> bot -> aoc -> get_uid($value['name'])) {							// If the player isn't on our buddy list, add it							if(!$this -> bot -> aoc -> buddy_exists($value['name']) $this -> bot -> aoc -> buddy_add($value['name']));							// Update status							if($this -> bot -> aoc -> buddy_online($value['name'])) {								mysql_query("UPDATE w_lookup STE status='1', stamp='".mktime()."' LIMIT 1");								$players[$key]['status'] = 1;							}							else {								mysql_query("UPDATE w_lookup STE status='0', stamp='".mktime()."' LIMIT 1");								$players[$key]['status'] = 0;						} 						else {							mysql_query("DELETE FROM w_lookup WHERE id='".$value['id']."' LIMIT 1");							unset($players[$key]);						}					}				} 				else {					mysql_query("DELETE FROM w_lookup WHERE id='".$value['id']."' LIMIT 1");					unset($players[$key]);				}			}								}	}		function buddy($name, $msg) {		global $players;		foreach($players as $key=>$value) {			if($name == $value['name']) {				if($value['expire']>mktime()) {					mysql_query("UPDATE w_lookup STE status='".$msg."', stamp='".mktime()."' LIMIT 1");					$players[$key]['status'] = $msg;				}				 else {					mysql_query("DELETE FROM w_lookup WHERE id='".$value['id']."' LIMIT 1");					unset($players[$key]);				 }			}		}	}}?>