Added full source code
This commit is contained in:
commit
33f8586698
1377 changed files with 123808 additions and 0 deletions
scripts/game/beta5/msg
119
scripts/game/beta5/msg/library.inc
Normal file
119
scripts/game/beta5/msg/library.inc
Normal file
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
class beta5_msg_library {
|
||||
var $index = array(
|
||||
'get',
|
||||
'getHeaders',
|
||||
'send',
|
||||
'sendInAlliance',
|
||||
'sendToPlanet',
|
||||
'sendToPlayer'
|
||||
);
|
||||
|
||||
function beta5_msg_library($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
// Lists custom folders for a player
|
||||
function getCustomFolders($pid) {
|
||||
$q = $this->db->query("SELECT id,name FROM custom_folder WHERE player = $pid ORDER BY name");
|
||||
$a = array();
|
||||
while ($r = dbFetchArray($q)) {
|
||||
$a[$r[0]] = $r[1];
|
||||
}
|
||||
return $a;
|
||||
}
|
||||
|
||||
// Creates a custom folder
|
||||
function createFolder($pid, $name) {
|
||||
$this->db->query("INSERT INTO custom_folder(name,player) VALUES('".addslashes($name)."',$pid)");
|
||||
}
|
||||
|
||||
// Renames a custom folder
|
||||
function renameFolder($fid, $name) {
|
||||
$this->db->query("UPDATE custom_folder SET name = '".addslashes($name)."' WHERE id=$fid");
|
||||
}
|
||||
|
||||
// Flushes messages from a folder
|
||||
function flushFolder($pid, $ft, $fid) {
|
||||
$qs = "UPDATE message SET deleted=TRUE WHERE player=$pid AND ftype='$ft'";
|
||||
if ($ft == 'CUS') {
|
||||
$qs .= " AND fcustom=$fid";
|
||||
}
|
||||
$this->db->query($qs);
|
||||
}
|
||||
|
||||
// Deletes a custom folder
|
||||
function deleteFolder($pid, $fid) {
|
||||
$this->db->query("UPDATE message SET deleted=TRUE WHERE player=$pid AND ftype='CUS' AND fcustom=$fid");
|
||||
$this->db->query("DELETE FROM custom_folder WHERE player=$pid AND id=$fid");
|
||||
}
|
||||
|
||||
// Get count of all messages in a player's folder
|
||||
function getAll($pid, $ft, $cfid = null) {
|
||||
$qs = "SELECT COUNT(*) FROM message WHERE player=$pid AND ftype='$ft' AND NOT deleted";
|
||||
if (!is_null($cfid)) {
|
||||
$qs .= " AND fcustom = $cfid";
|
||||
}
|
||||
$q = $this->db->query($qs);
|
||||
if (!($q && count($q) == 1)) {
|
||||
return 0;
|
||||
}
|
||||
list($r) = dbFetchArray($q);
|
||||
return $r;
|
||||
}
|
||||
|
||||
// Get count of new messages in a player's folder
|
||||
function getNew($pid, $ft = null, $cfid = null) {
|
||||
$qs = "SELECT COUNT(*) FROM message WHERE player=$pid AND is_new AND NOT deleted";
|
||||
if (!is_null($ft)) {
|
||||
$qs .= " AND ftype='$ft'";
|
||||
if (!is_null($cfid)) {
|
||||
$qs .= " AND fcustom = $cfid";
|
||||
}
|
||||
}
|
||||
$q = $this->db->query($qs);
|
||||
if (!($q && count($q) == 1)) {
|
||||
return 0;
|
||||
}
|
||||
list($r) = dbFetchArray($q);
|
||||
return $r;
|
||||
}
|
||||
|
||||
// Sets a message status to "read"
|
||||
function setRead($mId) {
|
||||
$this->db->query("UPDATE message SET is_new = FALSE WHERE id = $mId");
|
||||
}
|
||||
|
||||
// Sets a message as deleted
|
||||
function delete($mId, $pId) {
|
||||
$this->db->query("UPDATE message SET deleted = TRUE WHERE id = $mId AND player = $pId");
|
||||
}
|
||||
|
||||
// Moves a message
|
||||
function move($mId, $pId, $tTp, $tId) {
|
||||
$qs = "ftype='$tTp',fcustom=" . ($tTp == "CUS" ? $tId : "NULL");
|
||||
$this->db->query("UPDATE message SET $qs WHERE id = $mId AND player = $pId");
|
||||
}
|
||||
|
||||
|
||||
// Loads message formatting scripts
|
||||
function loadFormat($type, $lang, $player) {
|
||||
if (!is_null($this->formats[$type])) {
|
||||
return $this->formats[$type];
|
||||
}
|
||||
|
||||
$path = config::$main['scriptdir'] . "/game/beta5/msgformat/$lang/$type.inc";
|
||||
if (!(file_exists($path) && is_readable($path))) {
|
||||
return null;
|
||||
}
|
||||
require_once($path);
|
||||
eval('$this->formats[$type] = new msgformat_'.$type.'($this->lib->game);');
|
||||
$this->formats[$type]->game = $this->game;
|
||||
$this->formats[$type]->player = $player;
|
||||
return $this->formats[$type];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
63
scripts/game/beta5/msg/library/get.inc
Normal file
63
scripts/game/beta5/msg/library/get.inc
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
class beta5_msg_get {
|
||||
|
||||
function beta5_msg_get($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
// Returns complete information about a message
|
||||
function run($mId, $pid) {
|
||||
$q = $this->db->query("SELECT * FROM message WHERE id=$mId AND NOT deleted");
|
||||
if (!($q && dbCount($q) == 1)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$a1 = dbFetchHash($q);
|
||||
$a = array(
|
||||
"id" => $a1['id'],
|
||||
"player" => $a1['player'],
|
||||
"ftype" => trim($a1['ftype']),
|
||||
"cfid" => $a1['fcustom'],
|
||||
"replyto" => $al['reply_to'],
|
||||
"received" => $a1['sent_on']
|
||||
);
|
||||
$new = ($a1['is_new'] == 't');
|
||||
if (!$new) {
|
||||
$q2 = $this->db->query("SELECT COUNT(*) <> 0 FROM message WHERE reply_to=$mId AND player=$pid");
|
||||
list($replied) = dbFetchArray($q2);
|
||||
}
|
||||
|
||||
$q2 = $this->db->query("SELECT * FROM msg_".$a1['mtype']." WHERE id=$mId");
|
||||
if (!($q2 && dbCount($q2))) {
|
||||
return $a;
|
||||
}
|
||||
|
||||
$lg = getLanguage();
|
||||
$f = $this->lib->mainClass->loadFormat($a1['mtype'], $lg, $pid);
|
||||
if (is_null($f)) {
|
||||
return $a;
|
||||
}
|
||||
|
||||
if (dbCount($q2) == 1) {
|
||||
$f->data = dbFetchHash($q2);
|
||||
} else {
|
||||
$f->data = array();
|
||||
while ($r2 = dbFetchHash($q2))
|
||||
array_push($f->data, $r2);
|
||||
}
|
||||
$a["from"] = $f->getSender();
|
||||
$a["to"] = $f->getRecipient();
|
||||
$a["subject"] = $f->getSubject();
|
||||
$a["slink"] = $f->getSLink();
|
||||
$a["rlink"] = $f->getRLink();
|
||||
$a["replink"] = $f->getReplyLink();
|
||||
$a["text"] = $f->getContents();
|
||||
$a["status"] = $new ? "N" : ($replied ? "R" : "r");
|
||||
return $a;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
64
scripts/game/beta5/msg/library/getHeaders.inc
Normal file
64
scripts/game/beta5/msg/library/getHeaders.inc
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
class beta5_msg_getHeaders {
|
||||
|
||||
function beta5_msg_getHeaders($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
// Get headers for all messages inside a folder
|
||||
function run($pid, $fld, $cfid) {
|
||||
$lg = getLanguage();
|
||||
$qs = "player=$pid AND NOT deleted AND ftype='$fld'";
|
||||
if ($fld == "CUS") {
|
||||
$qs .= " AND fcustom=$cfid";
|
||||
}
|
||||
$q = $this->db->query("SELECT id,sent_on,mtype,is_new,reply_to FROM message WHERE $qs");
|
||||
|
||||
$a = array();
|
||||
while ($r = dbFetchArray($q)) {
|
||||
list($id,$mom,$type,$new,$rt) = $r;
|
||||
$new = ($new == 't');
|
||||
|
||||
if (!$new) {
|
||||
$q2 = $this->db->query("SELECT COUNT(*) FROM message WHERE reply_to=$id AND player=$pid");
|
||||
list($replied) = dbFetchArray($q2);
|
||||
}
|
||||
|
||||
$q2 = $this->db->query("SELECT * FROM msg_$type WHERE id=$id");
|
||||
if (!($q2 || dbCount($q2))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$f = $this->lib->mainClass->loadFormat($type, $lg, $pid);
|
||||
if (is_null($f)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dbCount($q2) == 1) {
|
||||
$f->data = dbFetchHash($q2);
|
||||
} else {
|
||||
$f->data = array();
|
||||
while ($r2 = dbFetchHash($q2))
|
||||
array_push($f->data, $r2);
|
||||
}
|
||||
$a[$id] = array(
|
||||
"received" => $mom,
|
||||
"from" => $f->getSender(),
|
||||
"to" => $f->getRecipient(),
|
||||
"subject" => $f->getSubject(),
|
||||
"slink" => $f->getSLink(),
|
||||
"rlink" => $f->getRLink(),
|
||||
"replink" => $f->getReplyLink(),
|
||||
"replyTo" => $rt,
|
||||
"status" => $new ? "N" : ($replied ? "R" : "r"),
|
||||
);
|
||||
}
|
||||
|
||||
return $a;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
51
scripts/game/beta5/msg/library/send.inc
Normal file
51
scripts/game/beta5/msg/library/send.inc
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
class beta5_msg_send {
|
||||
|
||||
function beta5_msg_send($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
// Sends a message
|
||||
function run($player, $mType, $mData, $folder = 'INT', $replyTo = null, $isNew = true) {
|
||||
$moment = time();
|
||||
|
||||
// Insert the message header
|
||||
$qs = "INSERT INTO message(player,sent_on,mtype,ftype,is_new" . (is_null($replyTo) ? "" : ",reply_to")
|
||||
. ") VALUES ($player,$moment,'$mType','$folder'," . ($isNew ? 'TRUE' : 'FALSE') . (is_null($replyTo) ? "" : ",$replyTo") . ")";
|
||||
$id = $this->db->query($qs);
|
||||
if (!$id) {
|
||||
logText("beta5/msg/send: failed to send message to player $player", LOG_WARNING);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_array($mData[0])) {
|
||||
// It's an array of arrays, insert multiple entries
|
||||
foreach ($mData as $msg) {
|
||||
$this->insertData($mType, $id, $msg);
|
||||
}
|
||||
} else {
|
||||
$this->insertData($mType, $id, $mData);
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
function insertData($mType, $id, $mData) {
|
||||
$fields = array_keys($mData);
|
||||
$qs = "INSERT INTO msg_$mType (id," . join(',', $fields) . ") VALUES ($id";
|
||||
foreach ($fields as $f) {
|
||||
if (is_null($mData[$f])) {
|
||||
$qs .= ",NULL";
|
||||
} else {
|
||||
$qs .= ",'" . addslashes($mData[$f]) . "'";
|
||||
}
|
||||
}
|
||||
$qs .= ")";
|
||||
$this->db->query($qs);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
63
scripts/game/beta5/msg/library/sendInAlliance.inc
Normal file
63
scripts/game/beta5/msg/library/sendInAlliance.inc
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
class beta5_msg_sendInAlliance {
|
||||
|
||||
function beta5_msg_sendInAlliance($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
$this->players = $this->lib->game->getLib('beta5/player');
|
||||
}
|
||||
|
||||
|
||||
// Sends a message from a player to his own alliance
|
||||
function run($src, $dst, $sub, $msg, $rep = null) {
|
||||
$moment = time();
|
||||
$pinf = $this->players->call('get', $src);
|
||||
if ($pinf['aid'] != $dst) {
|
||||
return false;
|
||||
}
|
||||
$tag = addslashes($pinf['alliance']);
|
||||
|
||||
if (!is_null($rep)) {
|
||||
$q = $this->db->query("SELECT original FROM message WHERE player=$src AND id=$rep");
|
||||
if ($q && dbCount($q)) {
|
||||
list($oriMsgId) = dbFetchArray($q);
|
||||
} else {
|
||||
$rep = null;
|
||||
}
|
||||
}
|
||||
|
||||
$qs = "INSERT INTO message(player,sent_on,mtype,ftype,is_new";
|
||||
$qs .= (!is_null($rep)?",reply_to":"") . ") VALUES (";
|
||||
$qs .= "$src,$moment,'alliance','OUT',FALSE" . (!is_null($rep)?",$rep":"") . ")";
|
||||
$this->db->query($qs);
|
||||
$q = $this->db->query("SELECT id FROM message WHERE player=$src AND sent_on=$moment AND ftype='OUT'");
|
||||
list($id) = dbFetchArray($q);
|
||||
$this->db->query("INSERT INTO msg_alliance VALUES($id,$src,$dst,'$tag','".addslashes($sub)."','".addslashes($msg)."')");
|
||||
|
||||
$pl = $this->db->query("SELECT id FROM player WHERE alliance=$dst AND a_status='IN' AND id <> $src");
|
||||
while ($r = dbFetchArray($pl)) {
|
||||
list($pid) = $r;
|
||||
|
||||
if (!(is_null($rep) || is_null($oriMsgId))) {
|
||||
$q = $this->db->query("SELECT id FROM message WHERE id=$oriMsgId OR original=$oriMsgId");
|
||||
if ($q && dbCount($q)) {
|
||||
list($plMsgId) = dbFetchArray($q);
|
||||
} else {
|
||||
$plMsgId = $oriMsgId;
|
||||
}
|
||||
}
|
||||
|
||||
$qs = "INSERT INTO message(player,sent_on,mtype,ftype,original";
|
||||
$qs .= (!is_null($rep)?",reply_to":"") . ") VALUES (";
|
||||
$qs .= "$pid,$moment,'alliance','IN',$id".(!is_null($rep)?",$plMsgId":"").")";
|
||||
$this->db->query($qs);
|
||||
|
||||
$q = $this->db->query("SELECT id FROM message WHERE player=$pid AND sent_on=$moment AND ftype='IN'");
|
||||
list($id2) = dbFetchArray($q);
|
||||
$this->db->query("INSERT INTO msg_alliance VALUES($id2,$src,$dst,'$tag','".addslashes($sub)."','".addslashes($msg)."')");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
51
scripts/game/beta5/msg/library/sendToPlanet.inc
Normal file
51
scripts/game/beta5/msg/library/sendToPlanet.inc
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
class beta5_msg_sendToPlanet {
|
||||
|
||||
function beta5_msg_sendToPlanet($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
$this->planets = $this->lib->game->getLib('beta5/planet');
|
||||
}
|
||||
|
||||
|
||||
// Sends a message from player to planet
|
||||
function run($src, $dst, $sub, $msg, $rep = null) {
|
||||
$moment = time();
|
||||
$pinf = $this->planets->call('byId', $dst);
|
||||
if (!is_null($rep)) {
|
||||
$q = $this->db->query("SELECT original FROM message WHERE player=$src AND id=$rep");
|
||||
if ($q && dbCount($q)) {
|
||||
list($oriMsgId) = dbFetchArray($q);
|
||||
} else {
|
||||
$rep = null;
|
||||
}
|
||||
}
|
||||
|
||||
$qs = "INSERT INTO message(player,sent_on,mtype,ftype,is_new";
|
||||
$qs .= (!is_null($rep)?",reply_to":"") . ") VALUES (";
|
||||
$qs .= "$src,$moment,'planet','OUT',FALSE" . (!is_null($rep)?",$rep":"") . ")";
|
||||
$this->db->query($qs);
|
||||
$q = $this->db->query("SELECT id FROM message WHERE player=$src AND sent_on=$moment AND ftype='OUT'");
|
||||
list($id) = dbFetchArray($q);
|
||||
$this->db->query(
|
||||
"INSERT INTO msg_planet VALUES($id,$dst,'".addslashes($pinf['name'])."',$src,"
|
||||
. "'".addslashes($sub)."','".addslashes($msg)."')"
|
||||
);
|
||||
|
||||
if (!is_null($pinf['owner'])) {
|
||||
$qs = "INSERT INTO message(player,sent_on,mtype,ftype,original";
|
||||
$qs .= (!is_null($rep)?",reply_to":"") . ") VALUES (";
|
||||
$qs .= $pinf['owner'].",$moment,'planet','IN',$id".(!is_null($rep)?",$oriMsgId":"").")";
|
||||
$this->db->query($qs);
|
||||
$q = $this->db->query("SELECT id FROM message WHERE player=".$pinf['owner']." AND sent_on=$moment AND ftype='IN'");
|
||||
list($id2) = dbFetchArray($q);
|
||||
$this->db->query(
|
||||
"INSERT INTO msg_planet VALUES($id2,$dst,'".addslashes($pinf['name'])."',$src,"
|
||||
. "'".addslashes($sub)."','".addslashes($msg)."')"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
36
scripts/game/beta5/msg/library/sendToPlayer.inc
Normal file
36
scripts/game/beta5/msg/library/sendToPlayer.inc
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
class beta5_msg_sendToPlayer {
|
||||
|
||||
function beta5_msg_sendToPlayer($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
// Sends a message from player to player
|
||||
function run($src, $dst, $sub, $msg, $rep = null) {
|
||||
$moment = time();
|
||||
if (is_null($rep)) {
|
||||
$oriMsgId = null;
|
||||
} else {
|
||||
$q = $this->db->query("SELECT original FROM message WHERE player=$src AND id=$rep");
|
||||
if ($q && dbCount($q)) {
|
||||
list($oriMsgId) = dbFetchArray($q);
|
||||
} else {
|
||||
$oriMsgId = $rep = null;
|
||||
}
|
||||
}
|
||||
|
||||
$message = array(
|
||||
"sender" => $src,
|
||||
"recipient" => $dst,
|
||||
"subject" => $sub,
|
||||
"message" => $msg
|
||||
);
|
||||
$this->lib->call('send', $src, 'std', $message, 'OUT', $rep, false);
|
||||
$this->lib->call('send', $dst, 'std', $message, 'IN', $oriMsgId);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Reference in a new issue