Exemple #1
0
function LoadConfig()
{
    $config_path = "/usr/local/opensauce/config.ini";
    if (empty($config_path)) {
        die("ERROR: config.ini path not yet set in config.php<br/>");
    }
    $config_file = parse_ini_file($config_path, true);
    if ($config_file == FALSE) {
        die("ERROR: failed to load config.ini from the defined path. (" . $config_path . ")<br/>");
    }
    $config = new ServerConfig();
    $config->ReadBlock($config_file);
    return $config;
}
Exemple #2
0
 protected function _dispatch($method, $params = null, $source = null)
 {
     $st = microtime(true);
     $content = $params[0];
     $mypre = "{$source}-{$method}";
     if ($content->lang == 4) {
         ServerConfig::setLang('en');
     }
     if ($content->lang == 3) {
         ServerConfig::setLang('zh');
     }
     CrabTools::mydump($params[0], REQ_DATA_ROOT . $mypre . '.param');
     Logger::info("{$source}::{$method}");
     try {
         $ret = parent::_dispatch($method, $params, $source);
         $parastr = print_r($params, true);
         $et = microtime(true);
         $cost = $et - $st;
         $cost = ceil(1000000 * $cost);
         Logger::info("{$source}::{$method}  {$cost} ,  [{$ret['status']}]  [{$ret['msg']}] {$parastr}");
         CrabTools::myprint($ret, REQ_DATA_ROOT . $mypre . '.resp');
         return $ret;
     } catch (Exception $e) {
         CrabTools::myprint($e, REQ_DATA_ROOT . $mypre . '.exp');
         return array('status' => 'error', 'msg' => 'exe exception');
     }
     Logger::error('Method "' . $method . '" auth failed' . " sk={$session_key} platform_id={$platform_id} ");
     return array('status' => 'error', 'msg' => 'auth failed');
 }
 public static function getdb_by_platformid($platformid)
 {
     $userid = AutoIncIdGenerator::genid($platformid);
     if ($userid) {
         return ServerConfig::connect_shop_mysql($userid, 1);
     }
 }
 /**
  * 
  * get a task from queue
  * called in worker client
  *
  * @param string $queue_name
  * @return ATask or something support serializing 
  *
  */
 public static function get($queue_name = 'defaultq')
 {
     $q = ServerConfig::connect_memcached('queue_memcacheq');
     if ($q) {
         $m = $q->get($queue_name);
     }
     return unserialize($m);
 }
Exemple #5
0
 /**
  * 结算收入
  *   
  * @param $params
  *    require   u      -- uid
  * @return 
  *    s   -- ok
  */
 public function checkout($params)
 {
     $uid = $params['u'];
     $db = ServerConfig::getdb_by_userid($uid);
     $ug = ModelFactory::UserGood();
     $ua = ModelFactory::UserAccount($db);
     $ret['s'] = 'ok';
     return $ret;
 }
 public function checkActionAccess($model)
 {
     if (!Yii::app()->user->isSuperuser() && ($model->hidden || !Yii::app()->user->can($model->server_id, 'manage commands', true))) {
         Yii::app()->user->deny();
     }
     $cfg = ServerConfig::model()->findByPk($model->server_id);
     if (!Yii::app()->user->isSuperuser() && (!$cfg || !$cfg->user_schedule)) {
         Yii::app()->user->deny();
     }
 }
Exemple #7
0
 protected function _dispatch($method, $params = null, $source = null)
 {
     $content = $params[0];
     ServerConfig::setLang($content->lang);
     return parent::_dispatch($method, $params, $source);
     $auth = $content->auth;
     if ($platform_id != null || $this->authOrkut($platform_id, $auth)) {
         return parent::_dispatch($method, $params, $source);
     }
     Logger::error('Method "' . $method . '" auth failed' . " auth={$auth} platform_id={$platform_id} ");
     return array('status' => 'error', 'msg' => 'auth failed');
 }
Exemple #8
0
 /**
  * 登录游戏
  *   
  * @param $params
  *    require   pid      -- platformid
  *    optional  anyfield  --头像等保存到 infos
  * @return 
  *    u      userid
  * 	  infos  map 玩家基本信息,头
  *    accs   map 玩家相关数值信息
  */
 public function login($params)
 {
     $pid = $params['pid'];
     $uid = AutoIncIdGenerator::genid($pid);
     $db = ServerConfig::getdb_by_userid($uid);
     $ua = ModelFactory::UserAccount($db);
     $uin = ModelFactory::UserInfo();
     $uin->put($params, $uid);
     $ret['s'] = 'ok';
     $ret['infos'] = $uin->get($uid);
     $ret['u'] = $uid;
     return $ret;
 }
 public static function init()
 {
     $file_path = Config::getSettingsDir() . 'config.ini';
     $array = array();
     $array = parse_ini_file($file_path);
     if (count($array) < 3) {
         error_log('config.ini info error, please check it!!!');
         return false;
     }
     self::$db_host = $array["dbHost"];
     self::$db_port = $array["dbPort"];
     self::$db_name = $array["dbName"];
     self::$db_user = $array["dbUser"];
     self::$db_password = $array["dbPwd"];
     return true;
 }
Exemple #10
0
 /**
  * 进货
  * @param $params
  * require  u  -- user_id
  * require  c  -- car be lold
  * require  g  -- the goods to be load
  * @return unknown_type
  * s   -- ok
  * c   -- car status
  * t   -- current time
  */
 public function go_goods($params)
 {
     //todo:添加购买验证逻辑
     //购买多个支持
     $uid = $params['u'];
     $car = ModelFactory::UserCar();
     $goods = ModelFactory::UserGood();
     $db = ServerConfig::getdb_by_userid($uid);
     $ua = ModelFactory::UserAccount($db);
     $car->put_super($params['c'], $uid);
     $item_count = 10;
     //货车容量从配置文件读取
     for ($i = 0; $i < $item_count; $i++) {
         $goods->put_super($params['c'], $uid);
     }
     $ret['s'] = 'ok';
     $ret['t'] = time();
     return $ret;
 }
Exemple #11
0
 protected function _dispatch($method, $params = null, $source = null)
 {
     $content = $params[0];
     return parent::_dispatch($method, $params, $source);
     $auth = $content->auth;
     ServerConfig::setLang($content->lang);
     if ($content->platform_id != null) {
         $platform_id = $content->platform_id;
     } else {
         if ($content->user_id != null) {
             $user_id = $content->user_id;
             $platform_id = AutoIncIdGenerator::getPlatformId($user_id);
         }
     }
     $vk = new Vk($platform_id);
     if ($vk->auth($auth)) {
         return parent::_dispatch($method, $params, $source);
     }
     Logger::error('Method "' . $method . '" auth failed' . " sk={$session_key} platform_id={$platform_id} ");
     return array('status' => 'error', 'msg' => 'auth failed');
 }
 public function actionIndex($id)
 {
     $sv = Server::model()->findByPk((int) $id);
     if (!$sv) {
         throw new Exception('Server not found');
     }
     $cfg = ServerConfig::model()->findByPk((int) $id);
     $pl = $sv->getOnlinePlayers();
     $st = $pl >= 0 ? 'online' : 'offline';
     $image = $this->getImg(Theme::themeFilePath('images/status/' . $this->banner));
     $statusIcon = $this->getImg(Theme::themeFilePath('images/status/' . $this->statusIcons[$st == 'online' ? 0 : 1]));
     $font = Theme::themeFilePath('images/status/' . $this->font);
     $color = imagecolorallocate($image, $this->color[0], $this->color[1], $this->color[2]);
     //Status icon
     imagecopy($image, $statusIcon, $this->textX, $this->iconY, 0, 0, imagesx($statusIcon), imagesy($statusIcon));
     imagedestroy($statusIcon);
     //Server name
     imagettftext($image, $this->titleSize, 0, $this->textX, $this->titleY, $color, $font, $sv->name);
     //Server IP
     $ipStr = trim($cfg && $cfg->display_ip ? $cfg->display_ip : $sv->ip);
     if (!strlen($ipStr) || $ipStr == '0.0.0.0') {
         if ($dmn = Daemon::model()->findByPk($sv->daemon_id)) {
             $ipStr = $dmn->ip;
         }
     }
     $ipStr = 'IP: ' . $ipStr . ':' . $sv->port;
     $sz = imagettfbbox($this->ipSize, 0, $font, $ipStr);
     imagettftext($image, $this->ipSize, 0, imagesx($image) - ($sz[2] - $sz[0]) - $this->ipOffset, $this->statusY, $color, $font, $ipStr);
     //Server status
     if ($st == 'online') {
         imagettftext($image, $this->statusSize, 0, $this->textX + $this->statusOffset, $this->statusY, $color, $font, $pl . ' / ' . $sv->players . ' ' . Yii::t('mc', 'Players'));
     } else {
         imagettftext($image, $this->statusSize, 0, $this->textX + $this->statusOffset, $this->statusY, $color, $font, Yii::t('mc', 'Offline'));
     }
     imagecolordeallocate($image, $color);
     header('Content-type: image/png');
     imagepng($image);
     imagedestroy($image);
 }
Exemple #13
0
 protected function _dispatch($method, $params = null, $source = null)
 {
     $content = $params[0];
     ServerConfig::setLang($content->lang);
     return parent::_dispatch($method, $params, $source);
     /*
     
     $session_key = $content->auth;
     if($content->platform_id !=null)
     {
     $platform_id = $content->platform_id;
     }
     else if($content->user_id !=null)
     {
     $user_id = $content->user_id;
     $platform_id = AutoIncIdGenerator::getPlatformId($user_id);
     }
     if($platform_id != null && $this->authRenren($platform_id,$session_key) ){
     return parent::_dispatch($method, $params, $source );
     }
     Logger::error('Method "' . $method . '" auth failed'." sk=$session_key platform_id=$platform_id ");
     return array('status'=>'error','msg'=>'auth failed');
     */
 }
Exemple #14
0
$renren->api_key = RenrenConfig::$api_key;
$renren->secret = RenrenConfig::$secret;
$renren->init();
$platform_id = "renren" . $renren->user;
$session_key = $renren->session_key;
$user_id = AutoIncIdGenerator::genid($platform_id);
$db = ServerConfig::getdb_by_userid($user_id);
$secret = Renrenconfig::$pay_secure;
//
if ($_POST['xn_sig_password'] != $secret) {
    echo "!!";
    exit;
}
$ua = ModelFactory::UserAccount($db);
$ua->find($user_id);
$order_db = ServerConfig::getdb_by_userid(0);
$order = ModelFactory::Order($order_db);
$order->find($_POST['xn_sig_order_number']);
if ($order->getAttr("is_paid")) {
    print json_encode(array('user_id' => $order->getAttr("platform_id"), 'amount' => $order->getAttr("amount"), 'order_number' => $order->getAttr("id")));
    exit;
}
$gem = $ua->getAttr("gem");
$gem += $order->getAttr("gem");
$ua->setAttr("gem", $gem);
$order->setAttr("is_paid", true);
$order->setAttr("paid_at", Date('Y-m-d H:i:s', time()));
if (!$order->save()) {
    Logger::error("order save error: " . $_POST['xn_sig_order_number']);
    print json_encode(array('user_id' => $order->getAttr("platform_id"), 'amount' => $order->getAttr("amount"), 'order_number' => $order->getAttr("id")));
    exit;
Exemple #15
0
 /**
  *
  * @param $md5
  * @return unknown_type
  */
 static function getMd5($md5)
 {
     if (!$md5) {
         return array();
     }
     $mc = ServerConfig::connect_memcached('cache_server');
     $key = $md5;
     if ($mc) {
         $ret = $mc->get($key, null);
     }
     if ($ret) {
         return $ret;
     }
     $db = ServerConfig::connect_mysql(BasicConfig::$text_mysql_db);
     $sql = "select * from `texts` where md5sign='{$md5}' ";
     $row = $db->fetchRow($sql);
     if ($row) {
         //alredy generated
         if ($mc) {
             $mc->add($key, $row);
         }
         return $row;
     }
     return $row;
 }
 public function actionCreateServer($name = '', $port = 0, $base = '', $players = 0, $no_commands = 0, $no_setup_script = 0)
 {
     $this->check();
     $model = $this->create('Server', array('name' => $name, 'port' => $port, 'dir' => $base, 'players' => $players), 'superuser');
     $cfg = new ServerConfig();
     $cfg->server_id = $model->id;
     $cfg->scenario = 'create';
     if (!$cfg->save()) {
         $this->end($cfg->errors);
     } else {
         if (!$no_commands) {
             $model->createDefaultCommands();
         }
         if (!$no_setup_script) {
             McBridge::get()->serverCmd($model->id, 'run_s:builtin:script setup');
         }
         $this->success();
     }
 }
Exemple #17
0
 /**
  * 接受礼物赠送
  * @param $params
  *   require  u         -- 受礼人id
  *            f         -- 送礼人id
  *            tag       -- 礼物种类
  * @return 
  *            s         --  OK
  */
 public function accept_gift($params)
 {
     $uid = $params['u'];
     $fid = $params['f'];
     $xid = $params['xid'];
     $msg = $params['msg'];
     if (0) {
         //验证xml中是否存在此物品
     }
     $db = ServerConfig::connect_main_mysql(0);
     $present = ModelFactory::Present($db);
     $gift = $present->findByIDs($uid, $fid, $xid);
     //验证逻辑
     if (!$gift) {
         $ret['s'] = 'notexsit';
         return $ret;
     }
     $tm = new TTMain();
     $gift_obj['tag'] = $gift['item_id'];
     $tm->put($gift_obj, $uid, TT::ITEM_GROUP);
     $ret['s'] = 'OK';
     return $ret;
 }
Exemple #18
0
<?php

//用户授权应用后的回调
//使用user_profiles 中的intparam2来记录用户的状态, -1来表示用户删除应用,1表示用户授权应用
include "./header.php";
$platform_id = "renren" . $renren->user;
$session_key = $renren->session_key;
$user_id = AutoIncIdGenerator::genid($platform_id);
$db = ServerConfig::getdb_by_userid($user_id);
$up = ModelFactory::UserProfile($db);
$up->find($user_id);
$up->setAttr("intparam2", 1);
$up->setAttr("intparam1", time());
$up->save();
 public function actionMysqlDb($id, $cmd = '')
 {
     Yii::app()->user->can($id, 'edit configs', true);
     $model = $this->loadModel($id);
     $settings = ServerConfig::model()->findByPk((int) $id);
     if (!strlen($model->mysqlHost) || !(Yii::app()->params['user_mysql'] && $settings->user_mysql || Yii::app()->user->isSuperuser())) {
         Yii::app()->user->deny();
     }
     if ($cmd == 'create') {
         if (!$model->createDatabase()) {
             Yii::app()->user->setFlash('server_error', Yii::t('mc', 'Failed to create MySQL database "{db}"!', array('{db}' => CHtml::encode($model->mysqlPrefix . $model->id))));
         }
         $this->redirect(array('mysqlDb', 'id' => $id));
     } else {
         if ($cmd == 'passwd') {
             if (!$model->changeDatabasePw()) {
                 Yii::app()->user->setFlash('server_error', Yii::t('mc', 'Failed to change MySQL password for "{db}"!', array('{db}' => CHtml::encode($model->mysqlPrefix . $model->id))));
             }
             $this->redirect(array('mysqlDb', 'id' => $id));
         } else {
             if ($cmd == 'delete') {
                 if (!$model->deleteDatabase()) {
                     Yii::app()->user->setFlash('server_error', Yii::t('mc', 'Failed to delete MySQL database "{db}"!', array('{db}' => CHtml::encode($model->mysqlPrefix . $model->id))));
                 }
                 $this->redirect(array('mysqlDb', 'id' => $id));
             }
         }
     }
     $this->render('mysqlDb', array('model' => $model, 'info' => $model->dbInfo));
 }
 public function getIpAuthRole()
 {
     $sc = ServerConfig::model()->findByPk($this->id);
     return $sc->ip_auth_role;
 }
Exemple #21
0
 /**
  * 仅仅用来和memcache打交道,请勿加 use_cache的判断!!
  * @param $key
  * @param $data
  * @param $keyname
  * @return unknown_type
  */
 public function setCacheData($key, &$data, $keyname = 'id')
 {
     $cache = ServerConfig::connect_memcached('cache_server');
     if ($cache) {
         $cid = "{$this->table_name}-{$keyname}-{$key}";
         return $cache->set($cid, $data);
     }
 }
 static function setid($id, $strKey, $strKeyName = 'userid')
 {
     $db = ServerConfig::connect_mysql(BasicConfig::$genid_mysql_db);
     $db->delete($strKeyName, "`id`={$id}");
     $db->delete($strKeyName, "keyvalue='{$strKey}'");
     $db->insert($strKeyName, array('keyvalue' => $strKey, 'id' => $id));
     $id = $db->lastInsertId();
     if ($id > 0) {
         //alredy generated
         self::cache_set($id, $strKey, $strKeyName);
         return $id;
     }
     throw new Exception(__METHOD__ . " failed id={$id} key='{$strKeyName}' value='{$strKey}'");
 }
 /**
  * Check if the current user has the permissions for $action. If $self is
  * true this means that the action is to be performed on the player
  * corresponding to the current user (checks 'self $action')
  */
 private function _can($role, $action, $server, $self)
 {
     if ($self) {
         $sc = ServerConfig::model()->findByPk((int) $server);
         if ($sc && isset($sc->{$action . '_role'})) {
             $svIdx = array_search($sc->{$action . '_role'}, User::$roles);
             $plIdx = array_search($role, User::$roles);
             return $plIdx >= $svIdx;
         }
         $action = 'self ' . $action;
     }
     $res = false;
     switch ($role) {
         case 'owner':
         case 'admin':
             $res |= in_array($action, array('control', 'stop', 'restart', 'manage players', 'edit', 'manage commands', 'start backup', 'command', 'edit configs', 'clear chat', 'clear log'));
         case 'mod':
             $res |= in_array($action, array('start', 'asay', 'get log', 'player details', 'summon', 'give', 'tp', 'kick', 'get backup'));
         case 'user':
             $res |= in_array($action, array('self give', 'self tp', 'get chat', 'chat', 'view player', 'view command'));
         case 'guest':
             $res |= in_array($action, array('get status', 'get players', 'view', 'self view player'));
         default:
     }
     return $res;
 }
Exemple #24
0
        $pro = urlencode($productVersion);
        $dom = urlencode($rootserver);
        $ipv = urlencode($_SERVER['REMOTE_ADDR']);
        $mai = urlencode($user_data['txtAdminEmail']);
        $string = "pro={$pro}&dom={$dom}&ipv={$ipv}&mai={$mai}";
        $contents = "no";
        $file = @fopen("http://www.iscripts.com/installtracker.php?{$string}", 'r');
        if ($file) {
            $contents = @fread($file, 8192);
        }
        $installed = true;
    }
}
//check current directory permissions
foreach ($directories as $dir) {
    $permission = ServerConfig::fileWritable($dir, str_replace("../", "", $dir));
    if (!$permission['status']) {
        $error = true;
        $serverPermission = "true";
        $error_message .= $permission['message'];
    }
}
if ($installed) {
    header("location: upgrade_success.php");
    exit;
}
/*
$lines = file($oldSettingsFile);
function get_value_of($name){
    global $lines;
    for($i=1; $i < count($lines);$i++){
Exemple #25
0
$weekday = date('N', $now);
$day_starttime = strtotime($datestr);
$day_endtime = $day_starttime + 86400;
echo "date:{$datestr} \nweekday:{$weekday}\n";
$mail_body .= "date:{$datestr} \nweekday:{$weekday}\n";
require_once '../../web/renren/renren.php';
$ren = new Renren();
$ren->api_key = 'a32cb73bea154d2c9d40703b66dc9142';
$ren->secret = '023a6201a9b04955b1af79b1e9037c16';
$ren->init();
$dbconfig = array('host' => '127.0.0.1', 'username' => 'admin', 'password' => '123456', 'port' => '3307', 'charset' => 'utf8', 'dbname' => 'mall_stat');
$cmd = "mysql -u{$dbconfig['username']} -P{$dbconfig['port']}  -h{$dbconfig['host']} ";
if ($dbconfig['password']) {
    $cmd .= " -p'{$dbconfig['password']}'";
}
$db = ServerConfig::connect_mysql($dbconfig);
function getModel($name)
{
    global $db;
    $m = new DBModel($name, false);
    $m->setDb($db);
    $m->useCache(false);
    return $m;
}
$g_dgm = getModel('daily_varibles');
function store_varible($pairs)
{
    if (!$pairs) {
        return;
    }
    global $g_dgm, $datestr, $db;
Exemple #26
0
            $attribs[] = array('label' => $form->labelEx($model, 'memory'), 'value' => $model->memory . ' ' . Yii::t('mc', 'MB'), 'cssClass' => 'adv');
        }
    }
    $attribs[] = array('label' => $form->labelEx($model, 'kick_delay'), 'type' => 'raw', 'cssClass' => 'adv', 'value' => $form->textField($model, 'kick_delay') . ' ' . $form->error($model, 'kick_delay'), 'hint' => Yii::t('mc', 'After how many milliseconds to kick players without access'));
    if (Yii::app()->user->isSuperuser() || $settings->user_schedule) {
        $attribs[] = array('label' => $form->labelEx($model, 'autosave'), 'type' => 'raw', 'cssClass' => 'adv', 'value' => $form->checkBox($model, 'autosave') . ' ' . $form->error($model, 'autosave'), 'hint' => Yii::t('mc', 'Regularly save the world to the disk'));
    }
    $attribs[] = array('label' => $form->labelEx($model, 'announce_save'), 'type' => 'raw', 'cssClass' => 'adv', 'value' => $form->checkBox($model, 'announce_save') . ' ' . $form->error($model, 'announce_save'), 'hint' => Yii::t('mc', 'Inform the players when the world has been saved'));
    if (Yii::app()->user->isSuperuser() || $edit && Yii::app()->params['user_chunkster']) {
        $attribs[] = array('label' => Yii::t('mc', 'Chunkster'), 'type' => 'raw', 'cssClass' => 'adv', 'value' => CHtml::submitButton(Yii::t('mc', 'Run Chunkster'), array('name' => 'chunkster', 'confirm' => Yii::t('mc', 'This tool will only run when your server has been fully stopped first. Use it at your own risk.'), 'submit' => '', 'params' => array('run_chunkster' => 'true'))), 'hint' => Yii::t('mc', 'Chunkster is a tool that can fix corrupted worlds. Use it at your own risk and create a backup first.'));
    }
    $this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => $attribs));
    $attribs = array();
    $attribs[] = array('label' => Yii::t('mc', 'Permissions'), 'value' => '', 'cssClass' => 'titlerow');
    if (Yii::app()->user->isSuperuser() || $settings->user_visibility) {
        $attribs[] = array('label' => $form->labelEx($settings, 'visible'), 'type' => 'raw', 'value' => $form->dropDownList($settings, 'visible', ServerConfig::getVisibility()) . ' ' . $form->error($settings, 'visible'), 'hint' => Yii::t('mc', 'Visibility in the Multicraft server list'));
        $attribs[] = array('label' => $form->labelEx($model, 'default_level'), 'type' => 'raw', 'value' => $form->dropDownList($model, 'default_level', $defaultRoles) . ' ' . $form->error($model, 'default_level'), 'hint' => Yii::t('mc', 'Role assigned to players on first connect ("No Access" for whitelisting)'));
    }
    $attribs[] = array('label' => $form->labelEx($settings, 'ip_auth_role'), 'type' => 'raw', 'value' => $form->dropDownList($settings, 'ip_auth_role', $ipRoles) . ' ' . $form->error($settings, 'ip_auth_role'), 'hint' => Yii::t('mc', 'For users whose IP matches a player ingame'));
    $attribs[] = array('label' => CHtml::label(Yii::t('mc', 'Cheat Role'), 'cheat_role'), 'type' => 'raw', 'value' => CHtml::dropDownList('cheat_role', $settings->give_role, $ipRoles), 'hint' => Yii::t('mc', 'Role required to use web based give/teleport'));
    $attribs[] = array('label' => '', 'type' => 'raw', 'value' => CHtml::submitButton($model->isNewRecord ? Yii::t('mc', 'Create') : Yii::t('mc', 'Save')));
    if (isset($data['resources'])) {
        $set = Setting::model()->findByPk('resourceCheckInterval');
        if (!$set || $set->value > 0) {
            echo '<div id="resources-ajax">' . $data['resources'] . '</div>';
        }
    }
    ?>
<br/>

<?php 
 public function init()
 {
     if (ServerConfig::init() === false) {
         $this->error("login", -1);
     }
 }
Exemple #28
0
<?php

require_once dirname(__FILE__) . "/../../base.php";
require_once MODEL_ROOT . "ModelFactory.php";
function test_invitation(&$db)
{
    $invit = ModelFactory::Invitation($db);
    $data = array('user_id' => 1, 'to_id' => 2, 'gift_id' => 3, 'is_accepted' => 1, 'updated_at' => date(TM_FORMAT, time()));
    $invit->insert($data);
}
function test_order(&$db)
{
    $order = ModelFactory::Order($db);
    $now = time();
    $data = array('order_id' => "order.{$now}", 'user_id' => 1, 'pid' => "pid.{$now}", 'amount' => 10, 'gem' => 20, 'is_paid' => 1, 'order_type' => "facebook", 'paid_at' => date(TM_FORMAT, $now), 'created_at' => date(TM_FORMAT, $now));
    $order->insert($data);
}
function test_present(&$db)
{
    $now = time();
    $present = ModelFactory::Present($db);
    $now = time();
    $data = array('user_id' => 1, 'donor_id' => 2, 'message' => 'wahaha', 'item_id' => 3, 'done' => 0, 'created_at' => date(TM_FORMAT, $now));
    $present->insert($data);
}
//$db = ServerConfig::getdb_by_userid(0);
$db = ServerConfig::connect_main_mysql(0);
//test_invitation( $db );
test_order($db);
//test_present($db);