forked from jxy918/swoole-game
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
357,955 additions
and
9 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
namespace Game\App; | ||
|
||
use Game\Core\BaseServer; | ||
use Game\Core\GameConst; | ||
use Game\Core\Dispatch; | ||
use Game\Core\Packet; | ||
|
||
/** | ||
* websocket服务器 | ||
*/ | ||
class GameServer extends BaseServer { | ||
/** | ||
* 是否开启http服务监听 | ||
* @var bool | ||
*/ | ||
protected $is_open_http = true; | ||
|
||
/** | ||
* 是否开启websocket监听 | ||
* @var bool | ||
*/ | ||
protected $is_open_tcp = true; | ||
|
||
/** | ||
* 全局db对象 | ||
*/ | ||
protected $db = null; | ||
|
||
/** | ||
* | ||
* 全局redis对象 | ||
*/ | ||
protected $redis = null; | ||
|
||
/** | ||
* 附件服务器初始化,例如:such as swoole atomic table or buffer 可以放置swoole的计数器,table等 | ||
*/ | ||
protected function init($serv){ | ||
|
||
} | ||
|
||
/** | ||
* WorkerStart时候可以调用, //require_once() 你要加载的处理方法函数等 what's you want load (such as framework init) | ||
* 比如需要动态加载的东西,可以做到无缝重启逻辑 | ||
*/ | ||
protected function initReload($server, $worker_id) { | ||
//自动加载, 可以通过reload更新 | ||
spl_autoload_register(function($classname) { | ||
if(file_exists(__DIR__.'/../lib/' . $classname . '.php')) { | ||
require_once __DIR__.'/../lib/' . $classname . '.php'; | ||
} | ||
if(file_exists(__DIR__.'/../app/' . $classname . '.php')) { | ||
require_once __DIR__ . '/../app/' . $classname . '.php'; | ||
} | ||
}); | ||
} | ||
|
||
|
||
|
||
public function initDB() { | ||
//初始化db | ||
//$this->db = new PdoDB(Config::getDbConf()); | ||
//$this->db->connect(); | ||
$conf = array( | ||
'host' => '192.168.1.85', | ||
'port' => 3308, | ||
'user' => 'web', | ||
'password' => 'aG98asg!($', | ||
'database' => 'accounts_mj' | ||
); | ||
$this->db = new MysqlPool($conf); | ||
$this->db = $this->db->get(); | ||
} | ||
|
||
public function initRedis() { | ||
//初始化redis | ||
$redis_conf = Config::getRedisConf(); | ||
$this->redis = new \Redis(); | ||
$this->redis->connect($redis_conf['host'], $redis_conf['port']); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
namespace Game\App\http; | ||
|
||
use Game\Core\AStrategy; | ||
|
||
/** | ||
* http测试逻辑 | ||
*/ | ||
|
||
class HttpTest extends AStrategy { | ||
/** | ||
* 执行方法 | ||
*/ | ||
public function exec() { | ||
//处理扣金币逻辑,暂时不处理原封不动发回去 | ||
return 'http test is ok!'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
namespace Game\App\tcp; | ||
|
||
use Game\Core\AStrategy; | ||
use Game\Core\Packet; | ||
use Game\Lib\protobuf\Person; | ||
|
||
/** | ||
* 测试tcp逻辑处理 | ||
*/ | ||
|
||
class TcpTest extends AStrategy { | ||
/** | ||
* 执行方法 | ||
*/ | ||
public function exec() { | ||
//解开protobuff数据,并输出 | ||
$data = $this->_params['data']; | ||
$obj = new Person(); | ||
$obj->parseFromString($data); | ||
echo $obj->getName() ."\n"; | ||
echo $obj->getEmail() ."\n"; | ||
echo $obj->getMoney() ."\n"; | ||
echo $obj->getId() . "\n"; | ||
|
||
//原样返回protobuf数据 | ||
$data = Packet::packEncode($data, 1, 1, 'protobuf'); | ||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
namespace Game\App\websock; | ||
|
||
use Game\Core\AStrategy; | ||
use Game\Core\Packet; | ||
use Game\conf\MainCmd; | ||
use Game\conf\SubCmdSys; | ||
|
||
/** | ||
* 取消翻倍 | ||
*/ | ||
|
||
class CancelCard extends AStrategy { | ||
/** | ||
* 执行方法 | ||
*/ | ||
public function exec() { | ||
//处理扣金币逻辑,暂时不处理原封不动发回去 | ||
$data = Packet::packFormat('OK', 0, $this->_params['data']); | ||
$data = Packet::packEncode($data, MainCmd::CMD_SYS, SubCmdSys::CANCEL_CARD_RESP); | ||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
namespace Game\App\websock; | ||
|
||
use Game\Core\AStrategy; | ||
use Game\Core\Packet; | ||
use Game\conf\MainCmd; | ||
use Game\conf\SubCmdSys; | ||
|
||
/** | ||
* 聊天消息回复 | ||
*/ | ||
|
||
class ChatMsg extends AStrategy { | ||
/** | ||
* 执行方法 | ||
*/ | ||
public function exec() { | ||
//原封不动发回去 | ||
$data = Packet::packFormat('OK', 0, $this->_params['data']); | ||
$data = Packet::packEncode($data, MainCmd::CMD_SYS, SubCmdSys::CHAT_MSG_RESP); | ||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
namespace Game\App\websock; | ||
|
||
use Game\Core\AStrategy; | ||
use Game\Core\Packet; | ||
use Game\Lib\JokerPoker; | ||
use Game\conf\MainCmd; | ||
use Game\conf\SubCmdSys; | ||
|
||
/** | ||
* 获取卡牌信息 | ||
*/ | ||
|
||
class GetCard extends AStrategy { | ||
/** | ||
* 执行方法 | ||
*/ | ||
public function exec() { | ||
$data = JokerPoker::getFiveCard(); | ||
$data = Packet::packFormat('OK', 0, $data); | ||
$data = Packet::packEncode($data, MainCmd::CMD_SYS, SubCmdSys::GET_CARD_RESP); | ||
// $this->testDB(); | ||
// $this->testRedis(); | ||
return $data; | ||
} | ||
|
||
/** | ||
* 测试db,根据自己情况使用 | ||
*/ | ||
public function testDB() { | ||
$sql = 'Call sp_account_get_by_uid(1000006)'; | ||
$sql_data = $this->_params['db']->queryAll($sql, ''); | ||
var_dump(__CLASS__.'=======>',$sql_data); | ||
} | ||
|
||
/** | ||
* 测试redis,,根据自己情况使用 | ||
*/ | ||
public function testRedis() { | ||
$res = $this->_params['redis']->set('test', 'aaaaaaaaceshithis 这是一个测试程序'); | ||
var_dump(__CLASS__.'=======>redis',$res); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
namespace Game\App\websock; | ||
|
||
use Game\Core\AStrategy; | ||
use Game\Core\Packet; | ||
use Game\Lib\JokerPoker; | ||
use Game\conf\MainCmd; | ||
use Game\conf\SubCmdSys; | ||
|
||
/** | ||
* 翻倍处理 | ||
*/ | ||
|
||
class GetSingerCard extends AStrategy { | ||
/** | ||
* 执行方法 | ||
*/ | ||
public function exec() { | ||
$card = JokerPoker::getOneCard(); | ||
$data = array('card'=>$card); | ||
$data = Packet::packFormat('OK', 0, $data); | ||
$data = Packet::packEncode($data, MainCmd::CMD_SYS, SubCmdSys::GET_SINGER_CARD_RESP); | ||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
namespace Game\App\websock; | ||
|
||
use Game\Core\AStrategy; | ||
use Game\Core\Packet; | ||
use Game\Lib\JokerPoker; | ||
use Game\conf\MainCmd; | ||
use Game\conf\SubCmdSys; | ||
|
||
|
||
/** | ||
* 翻倍处理 | ||
*/ | ||
|
||
class IsDouble extends AStrategy { | ||
/** | ||
* 执行方法 | ||
*/ | ||
public function exec() { | ||
$card = isset($this->_params['data']['card']) ? $this->_params['data']['card'] : 2; ;//明牌 | ||
$pos = isset($this->_params['data']['pos']) && ($this->_params['data']['pos'] < 4) ? intval($this->_params['data']['pos']) : 2;//我选中的位置 0123 | ||
$res = JokerPoker::getIsDoubleCard($card, $pos); | ||
$res['bean'] = 0; | ||
$res['bet'] = 0; | ||
$data = Packet::packFormat('OK', 0, $res); | ||
$data = Packet::packEncode($data, MainCmd::CMD_SYS, SubCmdSys::IS_DOUBLE_RESP); | ||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
namespace Game\App\websock; | ||
|
||
use Game\Core\AStrategy; | ||
use Game\Core\Packet; | ||
use Game\conf\MainCmd; | ||
use Game\conf\SubCmdSys; | ||
|
||
/** | ||
* 发牌信息 | ||
*/ | ||
|
||
class SendCard extends AStrategy { | ||
/** | ||
* 执行方法 | ||
*/ | ||
public function exec() { | ||
//处理扣金币逻辑,暂时不处理原封不动发回去 | ||
$data = Packet::packFormat('OK', 0, $this->_params['data']); | ||
$data = Packet::packEncode($data, MainCmd::CMD_SYS, SubCmdSys::SEND_CARD_RESP); | ||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
namespace Game\App\websock; | ||
|
||
use Game\Core\AStrategy; | ||
use Game\Core\Packet; | ||
use Game\Lib\JokerPoker; | ||
use Game\conf\MainCmd; | ||
use Game\conf\SubCmdSys; | ||
|
||
/** | ||
* 翻牌处理 | ||
*/ | ||
|
||
class TurnCard extends AStrategy { | ||
/** | ||
* 执行方法 | ||
*/ | ||
public function exec() { | ||
$card = isset($this->_params['data']['card']) ? $this->_params['data']['card'] : array(); | ||
$card = JokerPoker::getFiveCard($card); | ||
$res = JokerPoker::getCardType($card); | ||
$data = Packet::packFormat('OK', 0, $res); | ||
$data = Packet::packEncode($data, MainCmd::CMD_SYS, SubCmdSys::TURN_CARD_RESP); | ||
return $data; | ||
} | ||
} |
Oops, something went wrong.