├── README.md ├── client ├── Classes │ ├── AppDelegate.cpp │ ├── AppDelegate.h │ ├── ChoosePlayTypeLayer.cpp │ ├── ChoosePlayTypeLayer.h │ ├── GameLayer.cpp │ ├── GameLayer.h │ ├── GameScene.cpp │ ├── GameScene.h │ ├── Global.h │ ├── MySocket.cpp │ ├── MySocket.h │ ├── MyTextFieldTTF.cpp │ ├── MyTextFieldTTF.h │ ├── NetGameLayer.cpp │ ├── NetGameLayer.h │ ├── Player.cpp │ ├── Player.h │ ├── Poker.cpp │ ├── Poker.h │ ├── Rule.cpp │ ├── Rule.h │ ├── TextFieldTTF.cpp │ ├── TextFieldTTF.h │ └── protocol.pb.h └── Resources │ ├── bk.png │ ├── poker.png │ ├── show.jpg │ └── strings.xml └── server ├── bin ├── Start.bat ├── config │ ├── account_cfg.ini │ └── game_cfg.ini ├── gameServer.exe ├── log │ ├── account.log │ ├── game.log │ └── testLoginServer.log ├── loginServer.exe ├── protoc-gen-go.exe └── testLoginServer.exe ├── pkg └── windows_386 │ ├── example.a │ ├── example │ ├── bubblesort.a │ └── qsort.a │ ├── game_engine │ ├── cache │ │ ├── mysql.a │ │ └── redis.a │ ├── config.a │ ├── logs.a │ ├── protobuf │ │ └── github.com │ │ │ └── golang │ │ │ └── protobuf │ │ │ └── proto.a │ └── redis.a │ ├── game_info │ └── protocol.a │ ├── github.com │ ├── drone │ │ └── routes.a │ ├── game_engine │ │ ├── cache │ │ │ └── redis.a │ │ ├── config.a │ │ ├── data │ │ │ └── redis.a │ │ ├── i18n.a │ │ ├── logs.a │ │ ├── models.a │ │ ├── orm.a │ │ └── timer.a │ ├── go-sql-driver │ │ └── mysql.a │ ├── golang │ │ ├── protobuf │ │ │ ├── proto.a │ │ │ └── protoc-gen-go │ │ │ │ ├── descriptor.a │ │ │ │ ├── generator.a │ │ │ │ ├── internal │ │ │ │ └── grpc.a │ │ │ │ └── plugin.a │ │ └── snappy.a │ ├── jdamick │ │ └── kafka.a │ └── nats-io │ │ ├── nats.a │ │ ├── nats │ │ └── encoders │ │ │ └── builtin.a │ │ └── nuid.a │ └── server │ ├── account.a │ ├── balanceServer │ └── test.a │ ├── chat.a │ ├── gameServer │ └── game.a │ ├── global.a │ ├── loginServer │ └── account.a │ ├── player.a │ ├── protocol.a │ ├── share │ ├── global.a │ └── protocol.a │ └── world.a └── src ├── github.com ├── game_engine │ ├── cache │ │ └── redis │ │ │ ├── redis.go │ │ │ ├── redisApi.go │ │ │ └── redisApi_test.go │ ├── config │ │ ├── config.go │ │ ├── config_test │ │ │ ├── goods.go │ │ │ ├── goods.json │ │ │ └── goods.xls │ │ ├── json.go │ │ └── json_test.go │ ├── i18n │ │ ├── i18n.go │ │ ├── i18n_test.go │ │ └── locale_test.ini │ ├── logs │ │ ├── README.md │ │ ├── conn.go │ │ ├── conn_test.go │ │ ├── console.go │ │ ├── console_test.go │ │ ├── es │ │ │ └── es.go │ │ ├── file.go │ │ ├── file_test.go │ │ ├── log.go │ │ ├── smtp.go │ │ └── smtp_test.go │ ├── orm │ │ ├── README.md │ │ ├── cmd.go │ │ ├── cmd_utils.go │ │ ├── db.go │ │ ├── db_alias.go │ │ ├── db_mysql.go │ │ ├── db_oracle.go │ │ ├── db_postgres.go │ │ ├── db_sqlite.go │ │ ├── db_tables.go │ │ ├── db_tidb.go │ │ ├── db_utils.go │ │ ├── models.go │ │ ├── models_boot.go │ │ ├── models_fields.go │ │ ├── models_info_f.go │ │ ├── models_info_m.go │ │ ├── models_test.go │ │ ├── models_utils.go │ │ ├── orm.go │ │ ├── orm_conds.go │ │ ├── orm_log.go │ │ ├── orm_object.go │ │ ├── orm_querym2m.go │ │ ├── orm_queryset.go │ │ ├── orm_raw.go │ │ ├── orm_test.go │ │ ├── qb.go │ │ ├── qb_mysql.go │ │ ├── qb_tidb.go │ │ ├── types.go │ │ └── utils.go │ └── timer │ │ ├── timer.go │ │ └── timer_test.go └── golang │ └── protobuf │ ├── .gitignore │ ├── AUTHORS │ ├── CONTRIBUTORS │ ├── LICENSE │ ├── Make.protobuf │ ├── Makefile │ ├── README │ ├── jsonpb │ ├── jsonpb.go │ ├── jsonpb_test.go │ └── jsonpb_test_proto │ │ ├── Makefile │ │ ├── more_test_objects.proto │ │ └── test_objects.proto │ ├── proto │ ├── Makefile │ ├── all_test.go │ ├── clone.go │ ├── clone_test.go │ ├── decode.go │ ├── encode.go │ ├── equal.go │ ├── equal_test.go │ ├── extensions.go │ ├── extensions_test.go │ ├── lib.go │ ├── message_set.go │ ├── message_set_test.go │ ├── pointer_reflect.go │ ├── pointer_unsafe.go │ ├── properties.go │ ├── proto3_proto │ │ └── proto3.proto │ ├── proto3_test.go │ ├── size2_test.go │ ├── size_test.go │ ├── testdata │ │ ├── Makefile │ │ ├── golden_test.go │ │ └── test.proto │ ├── text.go │ ├── text_parser.go │ ├── text_parser_test.go │ └── text_test.go │ └── protoc-gen-go │ ├── Account.proto │ ├── Game.proto │ ├── Makefile │ ├── c++ proto.bat │ ├── copy_C++.bat │ ├── copy_go.bat │ ├── descriptor │ ├── Makefile │ └── descriptor.pb.golden │ ├── doc.go │ ├── generator │ ├── Makefile │ ├── generator.go │ └── name_test.go │ ├── go proto.bat │ ├── internal │ └── grpc │ │ └── grpc.go │ ├── link_grpc.go │ ├── main.go │ ├── plugin │ ├── Makefile │ └── plugin.pb.golden │ ├── protoc-gen-go.exe │ ├── protoc.exe │ └── testdata │ ├── Makefile │ ├── extension_base.proto │ ├── extension_extra.proto │ ├── extension_test.go │ ├── extension_user.proto │ ├── golden_test.go │ ├── grpc.proto │ ├── imp.pb.go.golden │ ├── imp.proto │ ├── imp2.proto │ ├── imp3.proto │ ├── main_test.go │ ├── multi │ ├── multi1.proto │ ├── multi2.proto │ └── multi3.proto │ ├── my_test │ ├── test.pb.go.golden │ └── test.proto │ └── proto3.proto ├── server ├── gameServer │ ├── deal2a.go │ ├── deal4c.go │ ├── game │ │ ├── csvConfig.go │ │ ├── equip.go │ │ ├── hangUp.go │ │ ├── hangUpCoast.go │ │ ├── init.go │ │ ├── item.go │ │ ├── models.go │ │ ├── player.go │ │ ├── sysConfig.go │ │ ├── town.go │ │ └── world.go │ └── main.go ├── loginServer │ ├── account │ │ ├── accountMsg.go │ │ ├── initAccount.go │ │ └── models.go │ ├── deal4c.go │ ├── deal4g.go │ └── main.go └── share │ ├── global │ ├── global.go │ └── locale_zh-CN.ini │ └── protocol │ ├── Account.pb.go │ └── Game.pb.go └── testServer └── testLoginServer ├── main.go └── testLoginServer.exe /README.md: -------------------------------------------------------------------------------- 1 | # doudizhu 2 | cocos2dx 斗地主客户端(测试服务器性能) 3 | https://github.com/hujunlong/doudizhu/blob/master/Resources/show.jpg 4 | 5 | -------------------------------------------------------------------------------- /client/Classes/AppDelegate.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/client/Classes/AppDelegate.cpp -------------------------------------------------------------------------------- /client/Classes/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #ifndef _APP_DELEGATE_H_ 2 | #define _APP_DELEGATE_H_ 3 | 4 | #include "cocos2d.h" 5 | 6 | /** 7 | @brief The cocos2d Application. 8 | 9 | The reason for implement as private inheritance is to hide some interface call by Director. 10 | */ 11 | 12 | class AppDelegate : private cocos2d::Application 13 | { 14 | public: 15 | AppDelegate(); 16 | virtual ~AppDelegate(); 17 | 18 | /** 19 | @brief Implement Director and Scene init code here. 20 | @return true Initialize success, app continue. 21 | @return false Initialize failed, app terminate. 22 | */ 23 | virtual bool applicationDidFinishLaunching(); 24 | 25 | /** 26 | @brief The function be called when the application enter background 27 | @param the pointer of the application 28 | */ 29 | virtual void applicationDidEnterBackground(); 30 | 31 | /** 32 | @brief The function be called when the application enter foreground 33 | @param the pointer of the application 34 | */ 35 | virtual void applicationWillEnterForeground(); 36 | 37 | void setResourceSearchResolution(); 38 | 39 | void createNetWork(); 40 | }; 41 | 42 | #endif // _APP_DELEGATE_H_ 43 | 44 | -------------------------------------------------------------------------------- /client/Classes/ChoosePlayTypeLayer.cpp: -------------------------------------------------------------------------------- 1 | #include "ChoosePlayTypeLayer.h" 2 | 3 | 4 | ChoosePlayTypeLayer::ChoosePlayTypeLayer(){ 5 | 6 | } 7 | 8 | ChoosePlayTypeLayer::~ChoosePlayTypeLayer(){ 9 | 10 | } 11 | 12 | bool ChoosePlayTypeLayer::init(){ 13 | 14 | Size visibleSize = Director::getInstance()->getVisibleSize(); 15 | CCSprite *bk = CCSprite::create("bk.png"); 16 | this->addChild(bk,0); 17 | bk->setAnchorPoint(ccp(0,0)); 18 | 19 | const char *tip; 20 | Dictionary* strings = Dictionary::createWithContentsOfFile("strings.xml"); 21 | 22 | tip = ((String *)strings->objectForKey("danji"))->getCString(); 23 | MenuItemFont* alone_menu = MenuItemFont::create(tip,this,menu_selector(ChoosePlayTypeLayer::menuAloneHandle)); 24 | alone_menu->setPosition(Point(visibleSize.width / 2 - 20, visibleSize.height/2 + 20)); 25 | 26 | 27 | tip = ((String*)strings->objectForKey("wangluo"))->getCString(); 28 | MenuItemFont* net_menu = MenuItemFont::create(tip,this,menu_selector(ChoosePlayTypeLayer::menuNetHandle)); 29 | net_menu->setPosition(Point(visibleSize.width / 2 - 20, visibleSize.height/2 - 20)); 30 | 31 | m_handle_menu = Menu::create(); 32 | m_handle_menu->addChild(alone_menu,2,0); 33 | m_handle_menu->addChild(net_menu,2,1); 34 | m_handle_menu->setPosition(CCPointZero); 35 | this->addChild(m_handle_menu,20); 36 | 37 | 38 | 39 | return true; 40 | } 41 | 42 | 43 | void ChoosePlayTypeLayer::menuAloneHandle(CCObject* sender){ 44 | 45 | auto scene = Scene::create(); 46 | auto layer = GameLayer::create(); 47 | scene->addChild(layer); 48 | Director::getInstance()->replaceScene(scene); 49 | 50 | } 51 | 52 | void ChoosePlayTypeLayer::menuNetHandle(CCObject* sender){ 53 | auto scene = Scene::create(); 54 | auto layer = NetGameLayer::create(); 55 | scene->addChild(layer); 56 | Director::getInstance()->replaceScene(scene); 57 | } -------------------------------------------------------------------------------- /client/Classes/ChoosePlayTypeLayer.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/client/Classes/ChoosePlayTypeLayer.h -------------------------------------------------------------------------------- /client/Classes/GameLayer.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/client/Classes/GameLayer.cpp -------------------------------------------------------------------------------- /client/Classes/GameLayer.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/client/Classes/GameLayer.h -------------------------------------------------------------------------------- /client/Classes/GameScene.cpp: -------------------------------------------------------------------------------- 1 | #include "GameScene.h" 2 | 3 | GameScene::GameScene(){ 4 | this->gameLayer = NULL; 5 | }; 6 | 7 | GameScene::~GameScene(){ 8 | 9 | }; 10 | 11 | bool GameScene::init(){ 12 | if(!Scene::init()){ 13 | return false; 14 | } 15 | 16 | gameLayer = ChoosePlayTypeLayer::create(); 17 | if(gameLayer == NULL){ 18 | return false; 19 | } 20 | this->addChild(gameLayer); 21 | 22 | return true; 23 | } 24 | -------------------------------------------------------------------------------- /client/Classes/GameScene.h: -------------------------------------------------------------------------------- 1 | #pragma 2 | 3 | #include "cocos2d.h" 4 | #include "ChoosePlayTypeLayer.h" 5 | 6 | using namespace cocos2d; 7 | using namespace CocosDenshion; 8 | 9 | class GameScene : public Scene{ 10 | public: 11 | GameScene(void); 12 | 13 | ~GameScene(void); 14 | 15 | virtual bool init(); 16 | 17 | CREATE_FUNC(GameScene); 18 | public: 19 | 20 | ChoosePlayTypeLayer* gameLayer; 21 | }; -------------------------------------------------------------------------------- /client/Classes/Global.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/client/Classes/Global.h -------------------------------------------------------------------------------- /client/Classes/MySocket.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/client/Classes/MySocket.cpp -------------------------------------------------------------------------------- /client/Classes/MySocket.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef _WIN32 4 | #include 5 | typedef int socklen_t; 6 | #else 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | typedef int SOCKET; 16 | #define INVALID_SOCKET -1 17 | #define SOCKET_ERROR -1 18 | 19 | #endif 20 | 21 | 22 | class ODSocket { 23 | 24 | public: 25 | ODSocket(SOCKET sock = INVALID_SOCKET); 26 | ~ODSocket(); 27 | 28 | // Create socket object for snd/recv data 29 | bool Create(int af, int type, int protocol = 0); 30 | 31 | // Connect socket 32 | bool Connect(const char* ip, unsigned short port); 33 | 34 | // Bind socket 35 | bool Bind(unsigned short port); 36 | 37 | // Listen socket 38 | bool Listen(int backlog = 500); 39 | 40 | // Accept socket 41 | bool Accept(ODSocket& s, char* fromip = NULL); 42 | 43 | // Send socket 44 | int Send(const char* body, int body_len, int flags =0); 45 | 46 | // Recv socket 47 | int Recv(char* buf, int len, int flags = 0); 48 | 49 | // Close socket 50 | int Close(); 51 | 52 | // Get errno 53 | int GetError(); 54 | 55 | //#pragma region just for win32 56 | static int Init(); 57 | static int Clean(); 58 | 59 | // Domain parse 60 | static bool DnsParse(const char* domain, char* ip); 61 | 62 | ODSocket& operator = (SOCKET s); 63 | 64 | operator SOCKET(); 65 | 66 | protected: 67 | SOCKET m_sock; 68 | }; -------------------------------------------------------------------------------- /client/Classes/MyTextFieldTTF.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/client/Classes/MyTextFieldTTF.cpp -------------------------------------------------------------------------------- /client/Classes/MyTextFieldTTF.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/client/Classes/MyTextFieldTTF.h -------------------------------------------------------------------------------- /client/Classes/NetGameLayer.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/client/Classes/NetGameLayer.cpp -------------------------------------------------------------------------------- /client/Classes/NetGameLayer.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/client/Classes/NetGameLayer.h -------------------------------------------------------------------------------- /client/Classes/Player.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/client/Classes/Player.cpp -------------------------------------------------------------------------------- /client/Classes/Player.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/client/Classes/Player.h -------------------------------------------------------------------------------- /client/Classes/Poker.cpp: -------------------------------------------------------------------------------- 1 | #include "Poker.h" 2 | #include "GameLayer.h" 3 | 4 | Poker::Poker():m_isSelect(false),m_isClick(false){ 5 | 6 | } 7 | 8 | Poker::~Poker(){ 9 | 10 | } 11 | 12 | Poker* Poker::create(const char *poker_name,const CCRect& rect){ 13 | Poker* pk = new Poker(); 14 | if (pk && pk->initWithFile(poker_name,rect)){ 15 | pk->autorelease(); 16 | return pk; 17 | } 18 | CC_SAFE_DELETE(pk); 19 | return pk; 20 | } 21 | 22 | void Poker::onEnter(){ 23 | CCSprite::onEnter(); 24 | 25 | touchListener = EventListenerTouchOneByOne::create(); 26 | touchListener->onTouchBegan = CC_CALLBACK_2(Poker::onTouchBegan,this); 27 | touchListener->onTouchMoved = CC_CALLBACK_2(Poker::onTouchMoved,this); 28 | touchListener->onTouchEnded = CC_CALLBACK_2(Poker::onTouchEnded,this); 29 | touchListener->setSwallowTouches(true); 30 | 31 | _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener,this); 32 | } 33 | 34 | 35 | void Poker::onExit(){ 36 | _eventDispatcher->removeEventListenersForTarget(this); 37 | CCSprite::onExit(); 38 | } 39 | 40 | 41 | bool Poker::onTouchBegan(CCTouch *pTouch, CCEvent *pEvent){ 42 | CCSize size = getContentSize(); 43 | CCRect rect(-size.width/2,-size.height/2,size.width,size.height); 44 | CCPoint ptouch = convertTouchToNodeSpaceAR(pTouch); 45 | if (rect.containsPoint(ptouch) && m_isClick){ 46 | if (!m_isSelect) 47 | selectPkTop(); 48 | else 49 | selectPkDown(); 50 | return true; 51 | } 52 | return false; 53 | } 54 | 55 | 56 | void Poker::onTouchMoved(CCTouch *pTouch, CCEvent *pEvent){ 57 | 58 | } 59 | 60 | void Poker::onTouchEnded(CCTouch *pTouch, CCEvent *pEvent){ 61 | 62 | } 63 | 64 | void Poker::onTouchCancelled(CCTouch *pTouch, CCEvent *pEvent){ 65 | 66 | } 67 | 68 | void Poker::showFront(){ 69 | if (m_PkType != Joker){ 70 | this->setTextureRect(CCRect(this->m_PkNum*pkWidth,this->m_PkType*pkHeight,pkWidth,pkHeight)); 71 | }else{ 72 | this->setTextureRect(CCRect((this->m_PkNum-BlackJoker)*pkWidth,this->m_PkType*pkHeight,pkWidth,pkHeight)); 73 | } 74 | } 75 | 76 | void Poker::showBack(){ 77 | this->setTextureRect(CCRect(PkBackNum*pkWidth,PKBack*pkHeight,pkWidth,pkHeight)); 78 | } 79 | 80 | Poker* Poker::copy(){ 81 | Poker* pk; 82 | if (m_PkType != Joker) 83 | pk = Poker::create("poker.png",CCRect(this->m_PkNum*pkWidth,this->m_PkType*pkHeight,pkWidth,pkHeight)); 84 | else 85 | pk = Poker::create("poker.png",CCRect((this->m_PkNum-BlackJoker)*pkWidth,this->m_PkType*pkHeight,pkWidth,pkHeight)); 86 | pk->m_isClick = this->m_isClick; 87 | pk->m_isSelect = this->m_isSelect; 88 | pk->setPkType(this->getPkType()); 89 | pk->setPkNum(this->getPkNum()); 90 | pk->m_gameMain = this->m_gameMain; 91 | return pk; 92 | } 93 | 94 | void Poker::setTouchPriority(int num){ 95 | _eventDispatcher->setPriority(touchListener,num); 96 | } 97 | 98 | void Poker::selectPkTop(){ 99 | this->m_isSelect = true; 100 | this->setPosition((ccp(getPositionX(),getPositionY() + pkTopHeight))); 101 | m_gameMain->getArrayPlayerOut()->addObject(this); 102 | //m_gameMain->PlayerOutPaiXu(m_gameMain->getArrPlayerOut()); 103 | } 104 | 105 | void Poker::selectPkDown(){ 106 | m_isSelect = false; 107 | this->setPosition(ccp(getPositionX(),getPositionY() - pkTopHeight)); 108 | m_gameMain->getArrayPlayerOut()->removeObject(this); 109 | } -------------------------------------------------------------------------------- /client/Classes/Poker.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/client/Classes/Poker.h -------------------------------------------------------------------------------- /client/Classes/Rule.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/client/Classes/Rule.cpp -------------------------------------------------------------------------------- /client/Classes/Rule.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/client/Classes/Rule.h -------------------------------------------------------------------------------- /client/Classes/TextFieldTTF.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/client/Classes/TextFieldTTF.cpp -------------------------------------------------------------------------------- /client/Classes/TextFieldTTF.h: -------------------------------------------------------------------------------- 1 | #ifndef __TextFieldTTF_H__ 2 | #define __TextFieldTTF_H__ 3 | 4 | #include "cocos2d.h" 5 | USING_NS_CC; 6 | 7 | class MyTextFieldTTF : public CCLayer,public CCTextFieldDelegate 8 | { 9 | public: 10 | bool init(); 11 | bool onTouchBegan(CCTouch*, CCEvent*); 12 | void CreateText(const char *tip,const Vec2& position); 13 | CREATE_FUNC(MyTextFieldTTF); 14 | private: 15 | CCTextFieldTTF* textEdit; 16 | }; 17 | 18 | #endif // __HELLOWORLD_SCENE_H__ 19 | -------------------------------------------------------------------------------- /client/Resources/bk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/client/Resources/bk.png -------------------------------------------------------------------------------- /client/Resources/poker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/client/Resources/poker.png -------------------------------------------------------------------------------- /client/Resources/show.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/client/Resources/show.jpg -------------------------------------------------------------------------------- /client/Resources/strings.xml: -------------------------------------------------------------------------------- 1 |  2 | dizhu 3 | 地主 4 | 5 | yifen 6 | 1分 7 | 8 | erfen 9 | 2分 10 | 11 | sanfen 12 | 3分 13 | 14 | bujiao 15 | 不叫 16 | 17 | buchu 18 | 不出 19 | 20 | chupai 21 | 出牌 22 | 23 | youwin 24 | 你赢了!!点击重新开始!! 25 | 26 | youlost 27 | 你输了!!点击重新开始!! 28 | 29 | youwin 30 | 你赢了!!点击重新开始!! 31 | 32 | -------------------------------------------------------------------------------- /server/bin/Start.bat: -------------------------------------------------------------------------------- 1 | echo "start loginServer.exe" 2 | start /min "loginServer" "loginServer.exe" 3 | 4 | ping -n 1 127.0>nul 5 | echo "start gameServer" 6 | start /min gameServer "gameServer.exe" 7 | 8 | -------------------------------------------------------------------------------- /server/bin/config/account_cfg.ini: -------------------------------------------------------------------------------- 1 | #账号服务器日志 2 | account_log_max = 100000 3 | 4 | #账号服务器 5 | login_listen_4c_ip = 0.0.0.0:8080 6 | login_listen_4game_ip = 0.0.0.0:8081 7 | 8 | #账号服务器sql 9 | mysql_user = root 10 | mysql_pwd = game9z 11 | mysql_ip = 192.168.1.207 12 | mysql_port = 3306 13 | mysql_db = orm_test 14 | 15 | #所以服务器列表 16 | 1 = 192.168.0.3:8082 17 | 2 = 192.168.0.4:8082 18 | 3 = 127.0.0.1:8082 19 | 20 | #指出新进玩家放入服务器 21 | new_3 = 127.0.0.1:8082 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /server/bin/config/game_cfg.ini: -------------------------------------------------------------------------------- 1 | #必须与账号服务器相同 2 | game_id = 3 3 | 4 | #账号服务器日志 5 | account_log_max = 100000 6 | 7 | #所在服务器的地址(server_2_accont_address 连接的账号服务器地址 server_address 服务器开放给玩家的地址 server_note_address 用来发送给账号服务器 通知玩家需要登录的游戏服) 8 | server_2_accont_address = 127.0.0.1:8081 9 | server_address = 0.0.0.0:8082 10 | server_note_address = 127.0.0.1:8082 11 | 12 | #定时上传服务器当前人数间隔时间(秒做单位) 13 | distance_time = 20 14 | 15 | #账号服务器sql 16 | mysql_user = root 17 | mysql_pwd = game9z 18 | mysql_ip = 192.168.1.207 19 | mysql_port = 3306 20 | mysql_db = orm_game 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /server/bin/gameServer.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/bin/gameServer.exe -------------------------------------------------------------------------------- /server/bin/log/game.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/bin/log/game.log -------------------------------------------------------------------------------- /server/bin/loginServer.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/bin/loginServer.exe -------------------------------------------------------------------------------- /server/bin/protoc-gen-go.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/bin/protoc-gen-go.exe -------------------------------------------------------------------------------- /server/bin/testLoginServer.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/bin/testLoginServer.exe -------------------------------------------------------------------------------- /server/pkg/windows_386/example.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/example.a -------------------------------------------------------------------------------- /server/pkg/windows_386/example/bubblesort.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/example/bubblesort.a -------------------------------------------------------------------------------- /server/pkg/windows_386/example/qsort.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/example/qsort.a -------------------------------------------------------------------------------- /server/pkg/windows_386/game_engine/cache/mysql.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/game_engine/cache/mysql.a -------------------------------------------------------------------------------- /server/pkg/windows_386/game_engine/cache/redis.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/game_engine/cache/redis.a -------------------------------------------------------------------------------- /server/pkg/windows_386/game_engine/config.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/game_engine/config.a -------------------------------------------------------------------------------- /server/pkg/windows_386/game_engine/logs.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/game_engine/logs.a -------------------------------------------------------------------------------- /server/pkg/windows_386/game_engine/protobuf/github.com/golang/protobuf/proto.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/game_engine/protobuf/github.com/golang/protobuf/proto.a -------------------------------------------------------------------------------- /server/pkg/windows_386/game_engine/redis.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/game_engine/redis.a -------------------------------------------------------------------------------- /server/pkg/windows_386/game_info/protocol.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/game_info/protocol.a -------------------------------------------------------------------------------- /server/pkg/windows_386/github.com/drone/routes.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/github.com/drone/routes.a -------------------------------------------------------------------------------- /server/pkg/windows_386/github.com/game_engine/cache/redis.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/github.com/game_engine/cache/redis.a -------------------------------------------------------------------------------- /server/pkg/windows_386/github.com/game_engine/config.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/github.com/game_engine/config.a -------------------------------------------------------------------------------- /server/pkg/windows_386/github.com/game_engine/data/redis.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/github.com/game_engine/data/redis.a -------------------------------------------------------------------------------- /server/pkg/windows_386/github.com/game_engine/i18n.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/github.com/game_engine/i18n.a -------------------------------------------------------------------------------- /server/pkg/windows_386/github.com/game_engine/logs.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/github.com/game_engine/logs.a -------------------------------------------------------------------------------- /server/pkg/windows_386/github.com/game_engine/models.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/github.com/game_engine/models.a -------------------------------------------------------------------------------- /server/pkg/windows_386/github.com/game_engine/orm.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/github.com/game_engine/orm.a -------------------------------------------------------------------------------- /server/pkg/windows_386/github.com/game_engine/timer.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/github.com/game_engine/timer.a -------------------------------------------------------------------------------- /server/pkg/windows_386/github.com/go-sql-driver/mysql.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/github.com/go-sql-driver/mysql.a -------------------------------------------------------------------------------- /server/pkg/windows_386/github.com/golang/protobuf/proto.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/github.com/golang/protobuf/proto.a -------------------------------------------------------------------------------- /server/pkg/windows_386/github.com/golang/protobuf/protoc-gen-go/descriptor.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/github.com/golang/protobuf/protoc-gen-go/descriptor.a -------------------------------------------------------------------------------- /server/pkg/windows_386/github.com/golang/protobuf/protoc-gen-go/generator.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/github.com/golang/protobuf/protoc-gen-go/generator.a -------------------------------------------------------------------------------- /server/pkg/windows_386/github.com/golang/protobuf/protoc-gen-go/internal/grpc.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/github.com/golang/protobuf/protoc-gen-go/internal/grpc.a -------------------------------------------------------------------------------- /server/pkg/windows_386/github.com/golang/protobuf/protoc-gen-go/plugin.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/github.com/golang/protobuf/protoc-gen-go/plugin.a -------------------------------------------------------------------------------- /server/pkg/windows_386/github.com/golang/snappy.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/github.com/golang/snappy.a -------------------------------------------------------------------------------- /server/pkg/windows_386/github.com/jdamick/kafka.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/github.com/jdamick/kafka.a -------------------------------------------------------------------------------- /server/pkg/windows_386/github.com/nats-io/nats.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/github.com/nats-io/nats.a -------------------------------------------------------------------------------- /server/pkg/windows_386/github.com/nats-io/nats/encoders/builtin.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/github.com/nats-io/nats/encoders/builtin.a -------------------------------------------------------------------------------- /server/pkg/windows_386/github.com/nats-io/nuid.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/github.com/nats-io/nuid.a -------------------------------------------------------------------------------- /server/pkg/windows_386/server/account.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/server/account.a -------------------------------------------------------------------------------- /server/pkg/windows_386/server/balanceServer/test.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/server/balanceServer/test.a -------------------------------------------------------------------------------- /server/pkg/windows_386/server/chat.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/server/chat.a -------------------------------------------------------------------------------- /server/pkg/windows_386/server/gameServer/game.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/server/gameServer/game.a -------------------------------------------------------------------------------- /server/pkg/windows_386/server/global.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/server/global.a -------------------------------------------------------------------------------- /server/pkg/windows_386/server/loginServer/account.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/server/loginServer/account.a -------------------------------------------------------------------------------- /server/pkg/windows_386/server/player.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/server/player.a -------------------------------------------------------------------------------- /server/pkg/windows_386/server/protocol.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/server/protocol.a -------------------------------------------------------------------------------- /server/pkg/windows_386/server/share/global.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/server/share/global.a -------------------------------------------------------------------------------- /server/pkg/windows_386/server/share/protocol.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/server/share/protocol.a -------------------------------------------------------------------------------- /server/pkg/windows_386/server/world.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/pkg/windows_386/server/world.a -------------------------------------------------------------------------------- /server/src/github.com/game_engine/cache/redis/redisApi.go: -------------------------------------------------------------------------------- 1 | package redis 2 | 3 | import ( 4 | "bytes" 5 | "encoding/gob" 6 | ) 7 | 8 | var redis_ *Client 9 | 10 | func init() { 11 | redis_ = new(Client) 12 | } 13 | 14 | type Role struct { 15 | Name string 16 | Gold int32 17 | } 18 | 19 | func Add(key string, inter interface{}) error { 20 | buf := bytes.NewBuffer(nil) 21 | enc := gob.NewEncoder(buf) 22 | err := enc.Encode(inter) 23 | if err == nil { 24 | err = redis_.Set(key, buf.Bytes()) 25 | } 26 | return err 27 | } 28 | 29 | func Modify(key string, inter interface{}) error { 30 | buf := bytes.NewBuffer(nil) 31 | enc := gob.NewEncoder(buf) 32 | err := enc.Encode(inter) 33 | if err == nil { 34 | err = redis_.Set(key, buf.Bytes()) 35 | } 36 | return err 37 | } 38 | 39 | func Find(key string, inter interface{}) error { 40 | data, err := redis_.Get(key) 41 | 42 | if err == nil { 43 | buf := bytes.NewBuffer(data) 44 | dec := gob.NewDecoder(buf) 45 | dec.Decode(inter) 46 | } 47 | return err 48 | } 49 | 50 | func Incr(key string) (int64, error) { 51 | id, err := redis_.Incr(key) 52 | return id, err 53 | } 54 | 55 | func Del(key string) (bool, error) { 56 | ok, err := redis_.Del(key) 57 | return ok, err 58 | } 59 | 60 | func Exists(key string) (bool, error) { 61 | result, err := redis_.Exists(key) 62 | return result, err 63 | } 64 | -------------------------------------------------------------------------------- /server/src/github.com/game_engine/cache/redis/redisApi_test.go: -------------------------------------------------------------------------------- 1 | package redis 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | type PlayerInfo struct { 8 | ID string 9 | Name string 10 | Age int32 11 | Sex int32 12 | } 13 | 14 | func showError(t *testing.T, err error) { 15 | if err != nil { 16 | t.Error(err) 17 | } 18 | } 19 | func TestRedisApi(t *testing.T) { 20 | player_info := PlayerInfo{"1111", "zhang", 12, 1} 21 | player_info2 := new(PlayerInfo) 22 | 23 | //add 24 | err := Add("1111", player_info) 25 | showError(t, err) 26 | 27 | //find 28 | err = Find("1111", player_info2) 29 | showError(t, err) 30 | 31 | //modify 32 | player_info = PlayerInfo{"2222", "zhang", 12, 1} 33 | err = Modify("1111", player_info) 34 | showError(t, err) 35 | 36 | //find 37 | err = Find("1111", player_info2) 38 | showError(t, err) 39 | if player_info2.ID != "2222" { 40 | t.Fatal("modify erro") 41 | } 42 | 43 | //del 44 | ok, err2 := Del("1111") 45 | showError(t, err2) 46 | if !ok { 47 | t.Fatal(err2) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /server/src/github.com/game_engine/config/config.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 beego Author. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Usage: 16 | // import( 17 | // "github.com/astaxie/beego/config" 18 | // ) 19 | // 20 | // cnf, err := config.NewConfig("ini", "config.conf") 21 | // 22 | // cnf APIS: 23 | // 24 | // cnf.Set(key, val string) error 25 | // cnf.String(key string) string 26 | // cnf.Strings(key string) []string 27 | // cnf.Int(key string) (int, error) 28 | // cnf.Int64(key string) (int64, error) 29 | // cnf.Bool(key string) (bool, error) 30 | // cnf.Float(key string) (float64, error) 31 | // cnf.DefaultString(key string, defaultval string) string 32 | // cnf.DefaultStrings(key string, defaultval []string) []string 33 | // cnf.DefaultInt(key string, defaultval int) int 34 | // cnf.DefaultInt64(key string, defaultval int64) int64 35 | // cnf.DefaultBool(key string, defaultval bool) bool 36 | // cnf.DefaultFloat(key string, defaultval float64) float64 37 | // cnf.DIY(key string) (interface{}, error) 38 | // cnf.GetSection(section string) (map[string]string, error) 39 | // cnf.SaveConfigFile(filename string) error 40 | // 41 | // more docs http://beego.me/docs/module/config.md 42 | package config 43 | 44 | import ( 45 | "fmt" 46 | ) 47 | 48 | // ConfigContainer defines how to get and set value from configuration raw data. 49 | type ConfigContainer interface { 50 | Set(key, val string) error // support section::key type in given key when using ini type. 51 | String(key string) string // support section::key type in key string when using ini and json type; Int,Int64,Bool,Float,DIY are same. 52 | Strings(key string) []string //get string slice 53 | Int(key string) (int, error) 54 | Int64(key string) (int64, error) 55 | Bool(key string) (bool, error) 56 | Float(key string) (float64, error) 57 | DefaultString(key string, defaultval string) string // support section::key type in key string when using ini and json type; Int,Int64,Bool,Float,DIY are same. 58 | DefaultStrings(key string, defaultval []string) []string //get string slice 59 | DefaultInt(key string, defaultval int) int 60 | DefaultInt64(key string, defaultval int64) int64 61 | DefaultBool(key string, defaultval bool) bool 62 | DefaultFloat(key string, defaultval float64) float64 63 | DIY(key string) (interface{}, error) 64 | GetSection(section string) (map[string]string, error) 65 | SaveConfigFile(filename string) error 66 | } 67 | 68 | // Config is the adapter interface for parsing config file to get raw data to ConfigContainer. 69 | type Config interface { 70 | Parse(key string) (ConfigContainer, error) 71 | ParseData(data []byte) (ConfigContainer, error) 72 | } 73 | 74 | var adapters = make(map[string]Config) 75 | 76 | // Register makes a config adapter available by the adapter name. 77 | // If Register is called twice with the same name or if driver is nil, 78 | // it panics. 79 | func Register(name string, adapter Config) { 80 | if adapter == nil { 81 | panic("config: Register adapter is nil") 82 | } 83 | if _, ok := adapters[name]; ok { 84 | panic("config: Register called twice for adapter " + name) 85 | } 86 | adapters[name] = adapter 87 | } 88 | 89 | // adapterName is ini/json/xml/yaml. 90 | // filename is the config file path. 91 | func NewConfig(adapterName, fileaname string) (ConfigContainer, error) { 92 | adapter, ok := adapters[adapterName] 93 | if !ok { 94 | return nil, fmt.Errorf("config: unknown adaptername %q (forgotten import?)", adapterName) 95 | } 96 | return adapter.Parse(fileaname) 97 | } 98 | 99 | // adapterName is ini/json/xml/yaml. 100 | // data is the config data. 101 | func NewConfigData(adapterName string, data []byte) (ConfigContainer, error) { 102 | adapter, ok := adapters[adapterName] 103 | if !ok { 104 | return nil, fmt.Errorf("config: unknown adaptername %q (forgotten import?)", adapterName) 105 | } 106 | return adapter.ParseData(data) 107 | } 108 | -------------------------------------------------------------------------------- /server/src/github.com/game_engine/config/config_test/goods.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "game_engine/config" 6 | ) 7 | 8 | func ErrorMsg(err error) { 9 | if err != nil { 10 | fmt.Println("error Msg:", err) 11 | } 12 | } 13 | 14 | type goods struct { 15 | } 16 | 17 | func main() { 18 | cnf, err := config.NewConfig("json", "goods.json") 19 | 20 | ErrorMsg(err) 21 | fmt.Println(cnf) 22 | 23 | rootArray, _ := cnf.DIY("rootArray") 24 | rootArrayCasted := rootArray.([]interface{}) 25 | if len(rootArrayCasted) <= 0 { 26 | fmt.Println("error config") 27 | return 28 | } 29 | 30 | for i := 0; i < len(rootArrayCasted); i++ { 31 | elem := rootArrayCasted[i].(map[string]interface{}) 32 | 33 | if elem["name"] == float64(1) { 34 | fmt.Println("come here") 35 | } 36 | 37 | fmt.Println(elem["id"]) 38 | fmt.Println(elem["name"]) 39 | fmt.Println(elem["discri"]) 40 | fmt.Println(elem["gold"]) 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /server/src/github.com/game_engine/config/config_test/goods.json: -------------------------------------------------------------------------------- 1 | [{"id":1,"name":"单刀","discri":"一把单刀,很牛B","gold":20},{"id":2,"name":"长矛","discri":"一把长矛,很牛B","gold":30},{"id":3,"name":"弓箭","discri":"百步穿杨","gold":62}] -------------------------------------------------------------------------------- /server/src/github.com/game_engine/config/config_test/goods.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/src/github.com/game_engine/config/config_test/goods.xls -------------------------------------------------------------------------------- /server/src/github.com/game_engine/i18n/i18n.go: -------------------------------------------------------------------------------- 1 | package il8n 2 | 3 | import ( 4 | "bufio" 5 | "io" 6 | "os" 7 | "strings" 8 | ) 9 | 10 | var ( 11 | path string 12 | Data map[interface{}]interface{} 13 | ) 14 | 15 | func init() { 16 | Data = make(map[interface{}]interface{}) 17 | path = "server/global/locale.ini" 18 | } 19 | 20 | func add2Map(str string) { 21 | str = strings.TrimSpace(str) 22 | if strings.HasPrefix(str, "#") { 23 | return 24 | } 25 | 26 | strs := strings.Split(str, "=") 27 | if len(strs) == 2 { 28 | key := strings.TrimSpace(strs[0]) //utf8 无 bom 29 | value := strings.TrimSpace(strs[1]) 30 | Data[key] = value 31 | } 32 | } 33 | 34 | func GetInit(path_ ...string) error { 35 | if len(path_) == 1 { 36 | path = path_[0] 37 | } 38 | inputFile, inputError := os.Open(path) 39 | if inputError != nil { 40 | return inputError 41 | } 42 | defer inputFile.Close() 43 | 44 | inputReader := bufio.NewReader(inputFile) 45 | for { 46 | inputString, readerError := inputReader.ReadString('\n') 47 | if (readerError == io.EOF) && (len(inputString) == 0) { 48 | return nil 49 | } else { 50 | add2Map(inputString) 51 | } 52 | } 53 | return nil 54 | } 55 | -------------------------------------------------------------------------------- /server/src/github.com/game_engine/i18n/i18n_test.go: -------------------------------------------------------------------------------- 1 | package il8n 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestI18n(t *testing.T) { 8 | err := GetInit("locale_test.ini") 9 | 10 | if len(Data) != 2 { 11 | t.Error("error for #") 12 | t.Error(len(Data)) 13 | } 14 | if err != nil { 15 | t.Errorf("error:%s", err) 16 | } 17 | if Data["hi"] != "aaa" { 18 | t.Errorf("cout = %s", Data["hi"]) 19 | } 20 | if Data["bye"] != "涨" { 21 | t.Error("data error") 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /server/src/github.com/game_engine/i18n/locale_test.ini: -------------------------------------------------------------------------------- 1 | hi = aaa 2 | bye = 涨 3 | #gdd = 1234 4 | #abc = 123 5 | 6 | 7 | -------------------------------------------------------------------------------- /server/src/github.com/game_engine/logs/README.md: -------------------------------------------------------------------------------- 1 | ## logs 2 | logs is a Go logs manager. It can use many logs adapters. The repo is inspired by `database/sql` . 3 | 4 | 5 | ## How to install? 6 | 7 | go get github.com/astaxie/beego/logs 8 | 9 | 10 | ## What adapters are supported? 11 | 12 | As of now this logs support console, file,smtp and conn. 13 | 14 | 15 | ## How to use it? 16 | 17 | First you must import it 18 | 19 | import ( 20 | "github.com/astaxie/beego/logs" 21 | ) 22 | 23 | Then init a Log (example with console adapter) 24 | 25 | log := NewLogger(10000) 26 | log.SetLogger("console", "") 27 | 28 | > the first params stand for how many channel 29 | 30 | Use it like this: 31 | 32 | log.Trace("trace") 33 | log.Info("info") 34 | log.Warn("warning") 35 | log.Debug("debug") 36 | log.Critical("critical") 37 | 38 | 39 | ## File adapter 40 | 41 | Configure file adapter like this: 42 | 43 | log := NewLogger(10000) 44 | log.SetLogger("file", `{"filename":"test.log"}`) 45 | 46 | 47 | ## Conn adapter 48 | 49 | Configure like this: 50 | 51 | log := NewLogger(1000) 52 | log.SetLogger("conn", `{"net":"tcp","addr":":7020"}`) 53 | log.Info("info") 54 | 55 | 56 | ## Smtp adapter 57 | 58 | Configure like this: 59 | 60 | log := NewLogger(10000) 61 | log.SetLogger("smtp", `{"username":"beegotest@gmail.com","password":"xxxxxxxx","host":"smtp.gmail.com:587","sendTos":["xiemengjun@gmail.com"]}`) 62 | log.Critical("sendmail critical") 63 | time.Sleep(time.Second * 30) 64 | -------------------------------------------------------------------------------- /server/src/github.com/game_engine/logs/conn.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 beego Author. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package logs 16 | 17 | import ( 18 | "encoding/json" 19 | "io" 20 | "log" 21 | "net" 22 | ) 23 | 24 | // ConnWriter implements LoggerInterface. 25 | // it writes messages in keep-live tcp connection. 26 | type ConnWriter struct { 27 | lg *log.Logger 28 | innerWriter io.WriteCloser 29 | ReconnectOnMsg bool `json:"reconnectOnMsg"` 30 | Reconnect bool `json:"reconnect"` 31 | Net string `json:"net"` 32 | Addr string `json:"addr"` 33 | Level int `json:"level"` 34 | } 35 | 36 | // create new ConnWrite returning as LoggerInterface. 37 | func NewConn() LoggerInterface { 38 | conn := new(ConnWriter) 39 | conn.Level = LevelTrace 40 | return conn 41 | } 42 | 43 | // init connection writer with json config. 44 | // json config only need key "level". 45 | func (c *ConnWriter) Init(jsonconfig string) error { 46 | return json.Unmarshal([]byte(jsonconfig), c) 47 | } 48 | 49 | // write message in connection. 50 | // if connection is down, try to re-connect. 51 | func (c *ConnWriter) WriteMsg(msg string, level int) error { 52 | if level > c.Level { 53 | return nil 54 | } 55 | if c.neddedConnectOnMsg() { 56 | err := c.connect() 57 | if err != nil { 58 | return err 59 | } 60 | } 61 | 62 | if c.ReconnectOnMsg { 63 | defer c.innerWriter.Close() 64 | } 65 | c.lg.Println(msg) 66 | return nil 67 | } 68 | 69 | // implementing method. empty. 70 | func (c *ConnWriter) Flush() { 71 | 72 | } 73 | 74 | // destroy connection writer and close tcp listener. 75 | func (c *ConnWriter) Destroy() { 76 | if c.innerWriter != nil { 77 | c.innerWriter.Close() 78 | } 79 | } 80 | 81 | func (c *ConnWriter) connect() error { 82 | if c.innerWriter != nil { 83 | c.innerWriter.Close() 84 | c.innerWriter = nil 85 | } 86 | 87 | conn, err := net.Dial(c.Net, c.Addr) 88 | if err != nil { 89 | return err 90 | } 91 | 92 | if tcpConn, ok := conn.(*net.TCPConn); ok { 93 | tcpConn.SetKeepAlive(true) 94 | } 95 | 96 | c.innerWriter = conn 97 | c.lg = log.New(conn, "", log.Ldate|log.Ltime) 98 | return nil 99 | } 100 | 101 | func (c *ConnWriter) neddedConnectOnMsg() bool { 102 | if c.Reconnect { 103 | c.Reconnect = false 104 | return true 105 | } 106 | 107 | if c.innerWriter == nil { 108 | return true 109 | } 110 | 111 | return c.ReconnectOnMsg 112 | } 113 | 114 | func init() { 115 | Register("conn", NewConn) 116 | } 117 | -------------------------------------------------------------------------------- /server/src/github.com/game_engine/logs/conn_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 beego Author. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package logs 16 | 17 | import ( 18 | "testing" 19 | ) 20 | 21 | func TestConn(t *testing.T) { 22 | log := NewLogger(1000) 23 | log.SetLogger("conn", `{"net":"tcp","addr":":7020"}`) 24 | log.Informational("informational") 25 | } 26 | -------------------------------------------------------------------------------- /server/src/github.com/game_engine/logs/console.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 beego Author. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package logs 16 | 17 | import ( 18 | "encoding/json" 19 | "log" 20 | "os" 21 | "runtime" 22 | ) 23 | 24 | type Brush func(string) string 25 | 26 | func NewBrush(color string) Brush { 27 | pre := "\033[" 28 | reset := "\033[0m" 29 | return func(text string) string { 30 | return pre + color + "m" + text + reset 31 | } 32 | } 33 | 34 | var colors = []Brush{ 35 | NewBrush("1;37"), // Emergency white 36 | NewBrush("1;36"), // Alert cyan 37 | NewBrush("1;35"), // Critical magenta 38 | NewBrush("1;31"), // Error red 39 | NewBrush("1;33"), // Warning yellow 40 | NewBrush("1;32"), // Notice green 41 | NewBrush("1;34"), // Informational blue 42 | NewBrush("1;34"), // Debug blue 43 | } 44 | 45 | // ConsoleWriter implements LoggerInterface and writes messages to terminal. 46 | type ConsoleWriter struct { 47 | lg *log.Logger 48 | Level int `json:"level"` 49 | } 50 | 51 | // create ConsoleWriter returning as LoggerInterface. 52 | func NewConsole() LoggerInterface { 53 | cw := &ConsoleWriter{ 54 | lg: log.New(os.Stdout, "", log.Ldate|log.Ltime), 55 | Level: LevelDebug, 56 | } 57 | return cw 58 | } 59 | 60 | // init console logger. 61 | // jsonconfig like '{"level":LevelTrace}'. 62 | func (c *ConsoleWriter) Init(jsonconfig string) error { 63 | if len(jsonconfig) == 0 { 64 | return nil 65 | } 66 | return json.Unmarshal([]byte(jsonconfig), c) 67 | } 68 | 69 | // write message in console. 70 | func (c *ConsoleWriter) WriteMsg(msg string, level int) error { 71 | if level > c.Level { 72 | return nil 73 | } 74 | if goos := runtime.GOOS; goos == "windows" { 75 | c.lg.Println(msg) 76 | return nil 77 | } 78 | c.lg.Println(colors[level](msg)) 79 | 80 | return nil 81 | } 82 | 83 | // implementing method. empty. 84 | func (c *ConsoleWriter) Destroy() { 85 | 86 | } 87 | 88 | // implementing method. empty. 89 | func (c *ConsoleWriter) Flush() { 90 | 91 | } 92 | 93 | func init() { 94 | Register("console", NewConsole) 95 | } 96 | -------------------------------------------------------------------------------- /server/src/github.com/game_engine/logs/console_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 beego Author. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package logs 16 | 17 | import ( 18 | "testing" 19 | ) 20 | 21 | // Try each log level in decreasing order of priority. 22 | func testConsoleCalls(bl *BeeLogger) { 23 | bl.Emergency("emergency") 24 | bl.Alert("alert") 25 | bl.Critical("critical") 26 | bl.Error("error") 27 | bl.Warning("warning") 28 | bl.Notice("notice") 29 | bl.Informational("informational") 30 | bl.Debug("debug") 31 | } 32 | 33 | // Test console logging by visually comparing the lines being output with and 34 | // without a log level specification. 35 | func TestConsole(t *testing.T) { 36 | log1 := NewLogger(10000) 37 | log1.EnableFuncCallDepth(true) 38 | log1.SetLogger("console", "") 39 | testConsoleCalls(log1) 40 | 41 | log2 := NewLogger(100) 42 | log2.SetLogger("console", `{"level":3}`) 43 | testConsoleCalls(log2) 44 | } 45 | 46 | func BenchmarkConsole(b *testing.B) { 47 | log := NewLogger(10000) 48 | log.EnableFuncCallDepth(true) 49 | log.SetLogger("console", "") 50 | for i := 0; i < b.N; i++ { 51 | log.Debug("debug") 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /server/src/github.com/game_engine/logs/es/es.go: -------------------------------------------------------------------------------- 1 | package es 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "fmt" 7 | "net" 8 | "net/url" 9 | "time" 10 | 11 | "github.com/astaxie/beego/logs" 12 | "github.com/belogik/goes" 13 | ) 14 | 15 | func NewES() logs.LoggerInterface { 16 | cw := &esLogger{ 17 | Level: logs.LevelDebug, 18 | } 19 | return cw 20 | } 21 | 22 | type esLogger struct { 23 | *goes.Connection 24 | DSN string `json:"dsn"` 25 | Level int `json:"level"` 26 | } 27 | 28 | // {"dsn":"http://localhost:9200/","level":1} 29 | func (el *esLogger) Init(jsonconfig string) error { 30 | err := json.Unmarshal([]byte(jsonconfig), el) 31 | if err != nil { 32 | return err 33 | } 34 | if el.DSN == "" { 35 | return errors.New("empty dsn") 36 | } else if u, err := url.Parse(el.DSN); err != nil { 37 | return err 38 | } else if u.Path == "" { 39 | return errors.New("missing prefix") 40 | } else if host, port, err := net.SplitHostPort(u.Host); err != nil { 41 | return err 42 | } else { 43 | conn := goes.NewConnection(host, port) 44 | el.Connection = conn 45 | } 46 | return nil 47 | } 48 | 49 | func (el *esLogger) WriteMsg(msg string, level int) error { 50 | if level > el.Level { 51 | return nil 52 | } 53 | t := time.Now() 54 | vals := make(map[string]interface{}) 55 | vals["@timestamp"] = t.Format(time.RFC3339) 56 | vals["@msg"] = msg 57 | d := goes.Document{ 58 | Index: fmt.Sprintf("%04d.%02d.%02d", t.Year(), t.Month(), t.Day()), 59 | Type: "logs", 60 | Fields: vals, 61 | } 62 | _, err := el.Index(d, nil) 63 | return err 64 | } 65 | 66 | func (el *esLogger) Destroy() { 67 | 68 | } 69 | 70 | func (el *esLogger) Flush() { 71 | 72 | } 73 | 74 | func init() { 75 | logs.Register("es", NewES) 76 | } 77 | -------------------------------------------------------------------------------- /server/src/github.com/game_engine/logs/file_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 beego Author. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package logs 16 | 17 | import ( 18 | "bufio" 19 | "fmt" 20 | "os" 21 | "strconv" 22 | "testing" 23 | "time" 24 | ) 25 | 26 | func TestFile(t *testing.T) { 27 | log := NewLogger(10000) 28 | log.SetLogger("file", `{"filename":"test.log"}`) 29 | log.Debug("debug") 30 | log.Informational("info") 31 | log.Notice("notice") 32 | log.Warning("warning") 33 | log.Error("error") 34 | log.Alert("alert") 35 | log.Critical("critical") 36 | log.Emergency("emergency") 37 | time.Sleep(time.Second * 4) 38 | f, err := os.Open("test.log") 39 | if err != nil { 40 | t.Fatal(err) 41 | } 42 | b := bufio.NewReader(f) 43 | linenum := 0 44 | for { 45 | line, _, err := b.ReadLine() 46 | if err != nil { 47 | break 48 | } 49 | if len(line) > 0 { 50 | linenum++ 51 | } 52 | } 53 | var expected = LevelDebug + 1 54 | if linenum != expected { 55 | t.Fatal(linenum, "not "+strconv.Itoa(expected)+" lines") 56 | } 57 | os.Remove("test.log") 58 | } 59 | 60 | func TestFile2(t *testing.T) { 61 | log := NewLogger(10000) 62 | log.SetLogger("file", fmt.Sprintf(`{"filename":"test2.log","level":%d}`, LevelError)) 63 | log.Debug("debug") 64 | log.Info("info") 65 | log.Notice("notice") 66 | log.Warning("warning") 67 | log.Error("error") 68 | log.Alert("alert") 69 | log.Critical("critical") 70 | log.Emergency("emergency") 71 | time.Sleep(time.Second * 4) 72 | f, err := os.Open("test2.log") 73 | if err != nil { 74 | t.Fatal(err) 75 | } 76 | b := bufio.NewReader(f) 77 | linenum := 0 78 | for { 79 | line, _, err := b.ReadLine() 80 | if err != nil { 81 | break 82 | } 83 | if len(line) > 0 { 84 | linenum++ 85 | } 86 | } 87 | var expected = LevelError + 1 88 | if linenum != expected { 89 | t.Fatal(linenum, "not "+strconv.Itoa(expected)+" lines") 90 | } 91 | os.Remove("test2.log") 92 | } 93 | 94 | func TestFileRotate(t *testing.T) { 95 | log := NewLogger(10000) 96 | log.SetLogger("file", `{"filename":"test3.log","maxlines":4}`) 97 | log.Debug("debug") 98 | log.Info("info") 99 | log.Notice("notice") 100 | log.Warning("warning") 101 | log.Error("error") 102 | log.Alert("alert") 103 | log.Critical("critical") 104 | log.Emergency("emergency") 105 | time.Sleep(time.Second * 4) 106 | rotatename := "test3.log" + fmt.Sprintf(".%s.%03d", time.Now().Format("2006-01-02"), 1) 107 | b, err := exists(rotatename) 108 | if !b || err != nil { 109 | t.Fatal("rotate not generated") 110 | } 111 | os.Remove(rotatename) 112 | os.Remove("test3.log") 113 | } 114 | 115 | func exists(path string) (bool, error) { 116 | _, err := os.Stat(path) 117 | if err == nil { 118 | return true, nil 119 | } 120 | if os.IsNotExist(err) { 121 | return false, nil 122 | } 123 | return false, err 124 | } 125 | 126 | func BenchmarkFile(b *testing.B) { 127 | log := NewLogger(100000) 128 | log.SetLogger("file", `{"filename":"test4.log"}`) 129 | for i := 0; i < b.N; i++ { 130 | log.Debug("debug") 131 | } 132 | os.Remove("test4.log") 133 | } 134 | -------------------------------------------------------------------------------- /server/src/github.com/game_engine/logs/smtp_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 beego Author. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package logs 16 | 17 | import ( 18 | "testing" 19 | "time" 20 | ) 21 | 22 | func TestSmtp(t *testing.T) { 23 | log := NewLogger(10000) 24 | log.SetLogger("smtp", `{"username":"beegotest@gmail.com","password":"xxxxxxxx","host":"smtp.gmail.com:587","sendTos":["xiemengjun@gmail.com"]}`) 25 | log.Critical("sendmail critical") 26 | time.Sleep(time.Second * 30) 27 | } 28 | -------------------------------------------------------------------------------- /server/src/github.com/game_engine/orm/README.md: -------------------------------------------------------------------------------- 1 | # beego orm 2 | 3 | [![Build Status](https://drone.io/github.com/astaxie/beego/status.png)](https://drone.io/github.com/astaxie/beego/latest) 4 | 5 | A powerful orm framework for go. 6 | 7 | It is heavily influenced by Django ORM, SQLAlchemy. 8 | 9 | **Support Database:** 10 | 11 | * MySQL: [github.com/go-sql-driver/mysql](https://github.com/go-sql-driver/mysql) 12 | * PostgreSQL: [github.com/lib/pq](https://github.com/lib/pq) 13 | * Sqlite3: [github.com/mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) 14 | 15 | Passed all test, but need more feedback. 16 | 17 | **Features:** 18 | 19 | * full go type support 20 | * easy for usage, simple CRUD operation 21 | * auto join with relation table 22 | * cross DataBase compatible query 23 | * Raw SQL query / mapper without orm model 24 | * full test keep stable and strong 25 | 26 | more features please read the docs 27 | 28 | **Install:** 29 | 30 | go get github.com/astaxie/beego/orm 31 | 32 | ## Changelog 33 | 34 | * 2013-08-19: support table auto create 35 | * 2013-08-13: update test for database types 36 | * 2013-08-13: go type support, such as int8, uint8, byte, rune 37 | * 2013-08-13: date / datetime timezone support very well 38 | 39 | ## Quick Start 40 | 41 | #### Simple Usage 42 | 43 | ```go 44 | package main 45 | 46 | import ( 47 | "fmt" 48 | "github.com/astaxie/beego/orm" 49 | _ "github.com/go-sql-driver/mysql" // import your used driver 50 | ) 51 | 52 | // Model Struct 53 | type User struct { 54 | Id int `orm:"auto"` 55 | Name string `orm:"size(100)"` 56 | } 57 | 58 | func init() { 59 | // register model 60 | orm.RegisterModel(new(User)) 61 | 62 | // set default database 63 | orm.RegisterDataBase("default", "mysql", "root:root@/my_db?charset=utf8", 30) 64 | } 65 | 66 | func main() { 67 | o := orm.NewOrm() 68 | 69 | user := User{Name: "slene"} 70 | 71 | // insert 72 | id, err := o.Insert(&user) 73 | 74 | // update 75 | user.Name = "astaxie" 76 | num, err := o.Update(&user) 77 | 78 | // read one 79 | u := User{Id: user.Id} 80 | err = o.Read(&u) 81 | 82 | // delete 83 | num, err = o.Delete(&u) 84 | } 85 | ``` 86 | 87 | #### Next with relation 88 | 89 | ```go 90 | type Post struct { 91 | Id int `orm:"auto"` 92 | Title string `orm:"size(100)"` 93 | User *User `orm:"rel(fk)"` 94 | } 95 | 96 | var posts []*Post 97 | qs := o.QueryTable("post") 98 | num, err := qs.Filter("User__Name", "slene").All(&posts) 99 | ``` 100 | 101 | #### Use Raw sql 102 | 103 | If you don't like ORM,use Raw SQL to query / mapping without ORM setting 104 | 105 | ```go 106 | var maps []Params 107 | num, err := o.Raw("SELECT id FROM user WHERE name = ?", "slene").Values(&maps) 108 | if num > 0 { 109 | fmt.Println(maps[0]["id"]) 110 | } 111 | ``` 112 | 113 | #### Transaction 114 | 115 | ```go 116 | o.Begin() 117 | ... 118 | user := User{Name: "slene"} 119 | id, err := o.Insert(&user) 120 | if err == nil { 121 | o.Commit() 122 | } else { 123 | o.Rollback() 124 | } 125 | 126 | ``` 127 | 128 | #### Debug Log Queries 129 | 130 | In development env, you can simple use 131 | 132 | ```go 133 | func main() { 134 | orm.Debug = true 135 | ... 136 | ``` 137 | 138 | enable log queries. 139 | 140 | output include all queries, such as exec / prepare / transaction. 141 | 142 | like this: 143 | 144 | ```go 145 | [ORM] - 2013-08-09 13:18:16 - [Queries/default] - [ db.Exec / 0.4ms] - [INSERT INTO `user` (`name`) VALUES (?)] - `slene` 146 | ... 147 | ``` 148 | 149 | note: not recommend use this in product env. 150 | 151 | ## Docs 152 | 153 | more details and examples in docs and test 154 | 155 | [documents](http://beego.me/docs/mvc/model/overview.md) 156 | 157 | -------------------------------------------------------------------------------- /server/src/github.com/game_engine/orm/db_mysql.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 beego Author. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package orm 16 | 17 | import ( 18 | "fmt" 19 | ) 20 | 21 | // mysql operators. 22 | var mysqlOperators = map[string]string{ 23 | "exact": "= ?", 24 | "iexact": "LIKE ?", 25 | "contains": "LIKE BINARY ?", 26 | "icontains": "LIKE ?", 27 | // "regex": "REGEXP BINARY ?", 28 | // "iregex": "REGEXP ?", 29 | "gt": "> ?", 30 | "gte": ">= ?", 31 | "lt": "< ?", 32 | "lte": "<= ?", 33 | "eq": "= ?", 34 | "ne": "!= ?", 35 | "startswith": "LIKE BINARY ?", 36 | "endswith": "LIKE BINARY ?", 37 | "istartswith": "LIKE ?", 38 | "iendswith": "LIKE ?", 39 | } 40 | 41 | // mysql column field types. 42 | var mysqlTypes = map[string]string{ 43 | "auto": "AUTO_INCREMENT NOT NULL PRIMARY KEY", 44 | "pk": "NOT NULL PRIMARY KEY", 45 | "bool": "bool", 46 | "string": "varchar(%d)", 47 | "string-text": "longtext", 48 | "time.Time-date": "date", 49 | "time.Time": "datetime", 50 | "int8": "tinyint", 51 | "int16": "smallint", 52 | "int32": "integer", 53 | "int64": "bigint", 54 | "uint8": "tinyint unsigned", 55 | "uint16": "smallint unsigned", 56 | "uint32": "integer unsigned", 57 | "uint64": "bigint unsigned", 58 | "float64": "double precision", 59 | "float64-decimal": "numeric(%d, %d)", 60 | } 61 | 62 | // mysql dbBaser implementation. 63 | type dbBaseMysql struct { 64 | dbBase 65 | } 66 | 67 | var _ dbBaser = new(dbBaseMysql) 68 | 69 | // get mysql operator. 70 | func (d *dbBaseMysql) OperatorSQL(operator string) string { 71 | return mysqlOperators[operator] 72 | } 73 | 74 | // get mysql table field types. 75 | func (d *dbBaseMysql) DbTypes() map[string]string { 76 | return mysqlTypes 77 | } 78 | 79 | // show table sql for mysql. 80 | func (d *dbBaseMysql) ShowTablesQuery() string { 81 | return "SELECT table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND table_schema = DATABASE()" 82 | } 83 | 84 | // show columns sql of table for mysql. 85 | func (d *dbBaseMysql) ShowColumnsQuery(table string) string { 86 | return fmt.Sprintf("SELECT COLUMN_NAME, COLUMN_TYPE, IS_NULLABLE FROM information_schema.columns "+ 87 | "WHERE table_schema = DATABASE() AND table_name = '%s'", table) 88 | } 89 | 90 | // execute sql to check index exist. 91 | func (d *dbBaseMysql) IndexExists(db dbQuerier, table string, name string) bool { 92 | row := db.QueryRow("SELECT count(*) FROM information_schema.statistics "+ 93 | "WHERE table_schema = DATABASE() AND table_name = ? AND index_name = ?", table, name) 94 | var cnt int 95 | row.Scan(&cnt) 96 | return cnt > 0 97 | } 98 | 99 | // create new mysql dbBaser. 100 | func newdbBaseMysql() dbBaser { 101 | b := new(dbBaseMysql) 102 | b.ins = b 103 | return b 104 | } 105 | -------------------------------------------------------------------------------- /server/src/github.com/game_engine/orm/db_oracle.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 beego Author. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package orm 16 | 17 | // oracle dbBaser 18 | type dbBaseOracle struct { 19 | dbBase 20 | } 21 | 22 | var _ dbBaser = new(dbBaseOracle) 23 | 24 | // create oracle dbBaser. 25 | func newdbBaseOracle() dbBaser { 26 | b := new(dbBaseOracle) 27 | b.ins = b 28 | return b 29 | } 30 | -------------------------------------------------------------------------------- /server/src/github.com/game_engine/orm/db_tidb.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 TiDB Author. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package orm 16 | 17 | import ( 18 | "fmt" 19 | ) 20 | 21 | // mysql dbBaser implementation. 22 | type dbBaseTidb struct { 23 | dbBase 24 | } 25 | 26 | var _ dbBaser = new(dbBaseTidb) 27 | 28 | // get mysql operator. 29 | func (d *dbBaseTidb) OperatorSQL(operator string) string { 30 | return mysqlOperators[operator] 31 | } 32 | 33 | // get mysql table field types. 34 | func (d *dbBaseTidb) DbTypes() map[string]string { 35 | return mysqlTypes 36 | } 37 | 38 | // show table sql for mysql. 39 | func (d *dbBaseTidb) ShowTablesQuery() string { 40 | return "SELECT table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND table_schema = DATABASE()" 41 | } 42 | 43 | // show columns sql of table for mysql. 44 | func (d *dbBaseTidb) ShowColumnsQuery(table string) string { 45 | return fmt.Sprintf("SELECT COLUMN_NAME, COLUMN_TYPE, IS_NULLABLE FROM information_schema.columns "+ 46 | "WHERE table_schema = DATABASE() AND table_name = '%s'", table) 47 | } 48 | 49 | // execute sql to check index exist. 50 | func (d *dbBaseTidb) IndexExists(db dbQuerier, table string, name string) bool { 51 | row := db.QueryRow("SELECT count(*) FROM information_schema.statistics "+ 52 | "WHERE table_schema = DATABASE() AND table_name = ? AND index_name = ?", table, name) 53 | var cnt int 54 | row.Scan(&cnt) 55 | return cnt > 0 56 | } 57 | 58 | // create new mysql dbBaser. 59 | func newdbBaseTidb() dbBaser { 60 | b := new(dbBaseTidb) 61 | b.ins = b 62 | return b 63 | } 64 | -------------------------------------------------------------------------------- /server/src/github.com/game_engine/orm/db_utils.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 beego Author. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package orm 16 | 17 | import ( 18 | "fmt" 19 | "reflect" 20 | "time" 21 | ) 22 | 23 | // get table alias. 24 | func getDbAlias(name string) *alias { 25 | if al, ok := dataBaseCache.get(name); ok { 26 | return al 27 | } 28 | panic(fmt.Errorf("unknown DataBase alias name %s", name)) 29 | } 30 | 31 | // get pk column info. 32 | func getExistPk(mi *modelInfo, ind reflect.Value) (column string, value interface{}, exist bool) { 33 | fi := mi.fields.pk 34 | 35 | v := ind.Field(fi.fieldIndex) 36 | if fi.fieldType&IsPostiveIntegerField > 0 { 37 | vu := v.Uint() 38 | exist = vu > 0 39 | value = vu 40 | } else if fi.fieldType&IsIntegerField > 0 { 41 | vu := v.Int() 42 | exist = vu > 0 43 | value = vu 44 | } else { 45 | vu := v.String() 46 | exist = vu != "" 47 | value = vu 48 | } 49 | 50 | column = fi.column 51 | return 52 | } 53 | 54 | // get fields description as flatted string. 55 | func getFlatParams(fi *fieldInfo, args []interface{}, tz *time.Location) (params []interface{}) { 56 | 57 | outFor: 58 | for _, arg := range args { 59 | val := reflect.ValueOf(arg) 60 | 61 | if arg == nil { 62 | params = append(params, arg) 63 | continue 64 | } 65 | 66 | kind := val.Kind() 67 | if kind == reflect.Ptr { 68 | val = val.Elem() 69 | kind = val.Kind() 70 | arg = val.Interface() 71 | } 72 | 73 | switch kind { 74 | case reflect.String: 75 | v := val.String() 76 | if fi != nil { 77 | if fi.fieldType == TypeDateField || fi.fieldType == TypeDateTimeField { 78 | var t time.Time 79 | var err error 80 | if len(v) >= 19 { 81 | s := v[:19] 82 | t, err = time.ParseInLocation(formatDateTime, s, DefaultTimeLoc) 83 | } else { 84 | s := v 85 | if len(v) > 10 { 86 | s = v[:10] 87 | } 88 | t, err = time.ParseInLocation(formatDate, s, tz) 89 | } 90 | if err == nil { 91 | if fi.fieldType == TypeDateField { 92 | v = t.In(tz).Format(formatDate) 93 | } else { 94 | v = t.In(tz).Format(formatDateTime) 95 | } 96 | } 97 | } 98 | } 99 | arg = v 100 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: 101 | arg = val.Int() 102 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: 103 | arg = val.Uint() 104 | case reflect.Float32: 105 | arg, _ = StrTo(ToStr(arg)).Float64() 106 | case reflect.Float64: 107 | arg = val.Float() 108 | case reflect.Bool: 109 | arg = val.Bool() 110 | case reflect.Slice, reflect.Array: 111 | if _, ok := arg.([]byte); ok { 112 | continue outFor 113 | } 114 | 115 | var args []interface{} 116 | for i := 0; i < val.Len(); i++ { 117 | v := val.Index(i) 118 | 119 | var vu interface{} 120 | if v.CanInterface() { 121 | vu = v.Interface() 122 | } 123 | 124 | if vu == nil { 125 | continue 126 | } 127 | 128 | args = append(args, vu) 129 | } 130 | 131 | if len(args) > 0 { 132 | p := getFlatParams(fi, args, tz) 133 | params = append(params, p...) 134 | } 135 | continue outFor 136 | case reflect.Struct: 137 | if v, ok := arg.(time.Time); ok { 138 | if fi != nil && fi.fieldType == TypeDateField { 139 | arg = v.In(tz).Format(formatDate) 140 | } else { 141 | arg = v.In(tz).Format(formatDateTime) 142 | } 143 | } else { 144 | typ := val.Type() 145 | name := getFullName(typ) 146 | var value interface{} 147 | if mmi, ok := modelCache.getByFN(name); ok { 148 | if _, vu, exist := getExistPk(mmi, val); exist { 149 | value = vu 150 | } 151 | } 152 | arg = value 153 | 154 | if arg == nil { 155 | panic(fmt.Errorf("need a valid args value, unknown table or value `%s`", name)) 156 | } 157 | } 158 | } 159 | 160 | params = append(params, arg) 161 | } 162 | return 163 | } 164 | -------------------------------------------------------------------------------- /server/src/github.com/game_engine/orm/models.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 beego Author. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package orm 16 | 17 | import ( 18 | "sync" 19 | ) 20 | 21 | const ( 22 | odCascade = "cascade" 23 | odSetNULL = "set_null" 24 | odSetDefault = "set_default" 25 | odDoNothing = "do_nothing" 26 | defaultStructTagName = "orm" 27 | defaultStructTagDelim = ";" 28 | ) 29 | 30 | var ( 31 | modelCache = &_modelCache{ 32 | cache: make(map[string]*modelInfo), 33 | cacheByFN: make(map[string]*modelInfo), 34 | } 35 | supportTag = map[string]int{ 36 | "-": 1, 37 | "null": 1, 38 | "index": 1, 39 | "unique": 1, 40 | "pk": 1, 41 | "auto": 1, 42 | "auto_now": 1, 43 | "auto_now_add": 1, 44 | "size": 2, 45 | "column": 2, 46 | "default": 2, 47 | "rel": 2, 48 | "reverse": 2, 49 | "rel_table": 2, 50 | "rel_through": 2, 51 | "digits": 2, 52 | "decimals": 2, 53 | "on_delete": 2, 54 | "type": 2, 55 | } 56 | ) 57 | 58 | // model info collection 59 | type _modelCache struct { 60 | sync.RWMutex 61 | orders []string 62 | cache map[string]*modelInfo 63 | cacheByFN map[string]*modelInfo 64 | done bool 65 | } 66 | 67 | // get all model info 68 | func (mc *_modelCache) all() map[string]*modelInfo { 69 | m := make(map[string]*modelInfo, len(mc.cache)) 70 | for k, v := range mc.cache { 71 | m[k] = v 72 | } 73 | return m 74 | } 75 | 76 | // get orderd model info 77 | func (mc *_modelCache) allOrdered() []*modelInfo { 78 | m := make([]*modelInfo, 0, len(mc.orders)) 79 | for _, table := range mc.orders { 80 | m = append(m, mc.cache[table]) 81 | } 82 | return m 83 | } 84 | 85 | // get model info by table name 86 | func (mc *_modelCache) get(table string) (mi *modelInfo, ok bool) { 87 | mi, ok = mc.cache[table] 88 | return 89 | } 90 | 91 | // get model info by field name 92 | func (mc *_modelCache) getByFN(name string) (mi *modelInfo, ok bool) { 93 | mi, ok = mc.cacheByFN[name] 94 | return 95 | } 96 | 97 | // set model info to collection 98 | func (mc *_modelCache) set(table string, mi *modelInfo) *modelInfo { 99 | mii := mc.cache[table] 100 | mc.cache[table] = mi 101 | mc.cacheByFN[mi.fullName] = mi 102 | if mii == nil { 103 | mc.orders = append(mc.orders, table) 104 | } 105 | return mii 106 | } 107 | 108 | // clean all model info. 109 | func (mc *_modelCache) clean() { 110 | mc.orders = make([]string, 0) 111 | mc.cache = make(map[string]*modelInfo) 112 | mc.cacheByFN = make(map[string]*modelInfo) 113 | mc.done = false 114 | } 115 | 116 | // ResetModelCache Clean model cache. Then you can re-RegisterModel. 117 | // Common use this api for test case. 118 | func ResetModelCache() { 119 | modelCache.clean() 120 | } 121 | -------------------------------------------------------------------------------- /server/src/github.com/game_engine/orm/models_info_m.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 beego Author. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package orm 16 | 17 | import ( 18 | "fmt" 19 | "os" 20 | "reflect" 21 | ) 22 | 23 | // single model info 24 | type modelInfo struct { 25 | pkg string 26 | name string 27 | fullName string 28 | table string 29 | model interface{} 30 | fields *fields 31 | manual bool 32 | addrField reflect.Value 33 | uniques []string 34 | isThrough bool 35 | } 36 | 37 | // new model info 38 | func newModelInfo(val reflect.Value) (info *modelInfo) { 39 | var ( 40 | err error 41 | fi *fieldInfo 42 | sf reflect.StructField 43 | ) 44 | 45 | info = &modelInfo{} 46 | info.fields = newFields() 47 | 48 | ind := reflect.Indirect(val) 49 | typ := ind.Type() 50 | 51 | info.addrField = val 52 | 53 | info.name = typ.Name() 54 | info.fullName = getFullName(typ) 55 | 56 | for i := 0; i < ind.NumField(); i++ { 57 | field := ind.Field(i) 58 | sf = ind.Type().Field(i) 59 | if sf.PkgPath != "" { 60 | continue 61 | } 62 | fi, err = newFieldInfo(info, field, sf) 63 | 64 | if err != nil { 65 | if err == errSkipField { 66 | err = nil 67 | continue 68 | } 69 | break 70 | } 71 | 72 | added := info.fields.Add(fi) 73 | if added == false { 74 | err = fmt.Errorf("duplicate column name: %s", fi.column) 75 | break 76 | } 77 | 78 | if fi.pk { 79 | if info.fields.pk != nil { 80 | err = fmt.Errorf("one model must have one pk field only") 81 | break 82 | } else { 83 | info.fields.pk = fi 84 | } 85 | } 86 | 87 | fi.fieldIndex = i 88 | fi.mi = info 89 | fi.inModel = true 90 | } 91 | 92 | if err != nil { 93 | fmt.Println(fmt.Errorf("field: %s.%s, %s", ind.Type(), sf.Name, err)) 94 | os.Exit(2) 95 | } 96 | 97 | return 98 | } 99 | 100 | // combine related model info to new model info. 101 | // prepare for relation models query. 102 | func newM2MModelInfo(m1, m2 *modelInfo) (info *modelInfo) { 103 | info = new(modelInfo) 104 | info.fields = newFields() 105 | info.table = m1.table + "_" + m2.table + "s" 106 | info.name = camelString(info.table) 107 | info.fullName = m1.pkg + "." + info.name 108 | 109 | fa := new(fieldInfo) 110 | f1 := new(fieldInfo) 111 | f2 := new(fieldInfo) 112 | fa.fieldType = TypeBigIntegerField 113 | fa.auto = true 114 | fa.pk = true 115 | fa.dbcol = true 116 | fa.name = "Id" 117 | fa.column = "id" 118 | fa.fullName = info.fullName + "." + fa.name 119 | 120 | f1.dbcol = true 121 | f2.dbcol = true 122 | f1.fieldType = RelForeignKey 123 | f2.fieldType = RelForeignKey 124 | f1.name = camelString(m1.table) 125 | f2.name = camelString(m2.table) 126 | f1.fullName = info.fullName + "." + f1.name 127 | f2.fullName = info.fullName + "." + f2.name 128 | f1.column = m1.table + "_id" 129 | f2.column = m2.table + "_id" 130 | f1.rel = true 131 | f2.rel = true 132 | f1.relTable = m1.table 133 | f2.relTable = m2.table 134 | f1.relModelInfo = m1 135 | f2.relModelInfo = m2 136 | f1.mi = info 137 | f2.mi = info 138 | 139 | info.fields.Add(fa) 140 | info.fields.Add(f1) 141 | info.fields.Add(f2) 142 | info.fields.pk = fa 143 | 144 | info.uniques = []string{f1.column, f2.column} 145 | return 146 | } 147 | -------------------------------------------------------------------------------- /server/src/github.com/game_engine/orm/orm_conds.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 beego Author. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package orm 16 | 17 | import ( 18 | "fmt" 19 | "strings" 20 | ) 21 | 22 | // ExprSep define the expression separation 23 | const ( 24 | ExprSep = "__" 25 | ) 26 | 27 | type condValue struct { 28 | exprs []string 29 | args []interface{} 30 | cond *Condition 31 | isOr bool 32 | isNot bool 33 | isCond bool 34 | } 35 | 36 | // Condition struct. 37 | // work for WHERE conditions. 38 | type Condition struct { 39 | params []condValue 40 | } 41 | 42 | // NewCondition return new condition struct 43 | func NewCondition() *Condition { 44 | c := &Condition{} 45 | return c 46 | } 47 | 48 | // And add expression to condition 49 | func (c Condition) And(expr string, args ...interface{}) *Condition { 50 | if expr == "" || len(args) == 0 { 51 | panic(fmt.Errorf(" args cannot empty")) 52 | } 53 | c.params = append(c.params, condValue{exprs: strings.Split(expr, ExprSep), args: args}) 54 | return &c 55 | } 56 | 57 | // AndNot add NOT expression to condition 58 | func (c Condition) AndNot(expr string, args ...interface{}) *Condition { 59 | if expr == "" || len(args) == 0 { 60 | panic(fmt.Errorf(" args cannot empty")) 61 | } 62 | c.params = append(c.params, condValue{exprs: strings.Split(expr, ExprSep), args: args, isNot: true}) 63 | return &c 64 | } 65 | 66 | // AndCond combine a condition to current condition 67 | func (c *Condition) AndCond(cond *Condition) *Condition { 68 | c = c.clone() 69 | if c == cond { 70 | panic(fmt.Errorf(" cannot use self as sub cond")) 71 | } 72 | if cond != nil { 73 | c.params = append(c.params, condValue{cond: cond, isCond: true}) 74 | } 75 | return c 76 | } 77 | 78 | // Or add OR expression to condition 79 | func (c Condition) Or(expr string, args ...interface{}) *Condition { 80 | if expr == "" || len(args) == 0 { 81 | panic(fmt.Errorf(" args cannot empty")) 82 | } 83 | c.params = append(c.params, condValue{exprs: strings.Split(expr, ExprSep), args: args, isOr: true}) 84 | return &c 85 | } 86 | 87 | // OrNot add OR NOT expression to condition 88 | func (c Condition) OrNot(expr string, args ...interface{}) *Condition { 89 | if expr == "" || len(args) == 0 { 90 | panic(fmt.Errorf(" args cannot empty")) 91 | } 92 | c.params = append(c.params, condValue{exprs: strings.Split(expr, ExprSep), args: args, isNot: true, isOr: true}) 93 | return &c 94 | } 95 | 96 | // OrCond combine a OR condition to current condition 97 | func (c *Condition) OrCond(cond *Condition) *Condition { 98 | c = c.clone() 99 | if c == cond { 100 | panic(fmt.Errorf(" cannot use self as sub cond")) 101 | } 102 | if cond != nil { 103 | c.params = append(c.params, condValue{cond: cond, isCond: true, isOr: true}) 104 | } 105 | return c 106 | } 107 | 108 | // IsEmpty check the condition arguments are empty or not. 109 | func (c *Condition) IsEmpty() bool { 110 | return len(c.params) == 0 111 | } 112 | 113 | // clone clone a condition 114 | func (c Condition) clone() *Condition { 115 | return &c 116 | } 117 | -------------------------------------------------------------------------------- /server/src/github.com/game_engine/orm/orm_object.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 beego Author. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package orm 16 | 17 | import ( 18 | "fmt" 19 | "reflect" 20 | ) 21 | 22 | // an insert queryer struct 23 | type insertSet struct { 24 | mi *modelInfo 25 | orm *orm 26 | stmt stmtQuerier 27 | closed bool 28 | } 29 | 30 | var _ Inserter = new(insertSet) 31 | 32 | // insert model ignore it's registered or not. 33 | func (o *insertSet) Insert(md interface{}) (int64, error) { 34 | if o.closed { 35 | return 0, ErrStmtClosed 36 | } 37 | val := reflect.ValueOf(md) 38 | ind := reflect.Indirect(val) 39 | typ := ind.Type() 40 | name := getFullName(typ) 41 | if val.Kind() != reflect.Ptr { 42 | panic(fmt.Errorf(" cannot use non-ptr model struct `%s`", name)) 43 | } 44 | if name != o.mi.fullName { 45 | panic(fmt.Errorf(" need model `%s` but found `%s`", o.mi.fullName, name)) 46 | } 47 | id, err := o.orm.alias.DbBaser.InsertStmt(o.stmt, o.mi, ind, o.orm.alias.TZ) 48 | if err != nil { 49 | return id, err 50 | } 51 | if id > 0 { 52 | if o.mi.fields.pk.auto { 53 | if o.mi.fields.pk.fieldType&IsPostiveIntegerField > 0 { 54 | ind.Field(o.mi.fields.pk.fieldIndex).SetUint(uint64(id)) 55 | } else { 56 | ind.Field(o.mi.fields.pk.fieldIndex).SetInt(id) 57 | } 58 | } 59 | } 60 | return id, nil 61 | } 62 | 63 | // close insert queryer statement 64 | func (o *insertSet) Close() error { 65 | if o.closed { 66 | return ErrStmtClosed 67 | } 68 | o.closed = true 69 | return o.stmt.Close() 70 | } 71 | 72 | // create new insert queryer. 73 | func newInsertSet(orm *orm, mi *modelInfo) (Inserter, error) { 74 | bi := new(insertSet) 75 | bi.orm = orm 76 | bi.mi = mi 77 | st, query, err := orm.alias.DbBaser.PrepareInsert(orm.db, mi) 78 | if err != nil { 79 | return nil, err 80 | } 81 | if Debug { 82 | bi.stmt = newStmtQueryLog(orm.alias, st, query) 83 | } else { 84 | bi.stmt = st 85 | } 86 | return bi, nil 87 | } 88 | -------------------------------------------------------------------------------- /server/src/github.com/game_engine/orm/qb.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 beego Author. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package orm 16 | 17 | import "errors" 18 | 19 | // QueryBuilder is the Query builder interface 20 | type QueryBuilder interface { 21 | Select(fields ...string) QueryBuilder 22 | From(tables ...string) QueryBuilder 23 | InnerJoin(table string) QueryBuilder 24 | LeftJoin(table string) QueryBuilder 25 | RightJoin(table string) QueryBuilder 26 | On(cond string) QueryBuilder 27 | Where(cond string) QueryBuilder 28 | And(cond string) QueryBuilder 29 | Or(cond string) QueryBuilder 30 | In(vals ...string) QueryBuilder 31 | OrderBy(fields ...string) QueryBuilder 32 | Asc() QueryBuilder 33 | Desc() QueryBuilder 34 | Limit(limit int) QueryBuilder 35 | Offset(offset int) QueryBuilder 36 | GroupBy(fields ...string) QueryBuilder 37 | Having(cond string) QueryBuilder 38 | Update(tables ...string) QueryBuilder 39 | Set(kv ...string) QueryBuilder 40 | Delete(tables ...string) QueryBuilder 41 | InsertInto(table string, fields ...string) QueryBuilder 42 | Values(vals ...string) QueryBuilder 43 | Subquery(sub string, alias string) string 44 | String() string 45 | } 46 | 47 | // NewQueryBuilder return the QueryBuilder 48 | func NewQueryBuilder(driver string) (qb QueryBuilder, err error) { 49 | if driver == "mysql" { 50 | qb = new(MySQLQueryBuilder) 51 | } else if driver == "tidb" { 52 | qb = new(TiDBQueryBuilder) 53 | } else if driver == "postgres" { 54 | err = errors.New("postgres query builder is not supported yet") 55 | } else if driver == "sqlite" { 56 | err = errors.New("sqlite query builder is not supported yet") 57 | } else { 58 | err = errors.New("unknown driver for query builder") 59 | } 60 | return 61 | } 62 | -------------------------------------------------------------------------------- /server/src/github.com/game_engine/timer/timer.go: -------------------------------------------------------------------------------- 1 | package timer 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "strconv" 7 | "strings" 8 | "time" 9 | ) 10 | 11 | func findInputIsError(input [6]int) error { 12 | for data := range input { 13 | if data < 0 { 14 | return errors.New("input have less 0") 15 | } 16 | } 17 | 18 | if input[1] > 12 { //月 19 | return errors.New("input month error more than 12") 20 | } 21 | 22 | //日 23 | leap_year := false 24 | if (input[0]%4 == 0 && input[0]%100 != 0) || (input[0]%400 == 0) { 25 | leap_year = true 26 | } 27 | 28 | switch input[1] { 29 | case 2: 30 | if leap_year { 31 | if input[2] > 28 { 32 | return errors.New("February, more than 28") 33 | } 34 | } else { 35 | if input[2] > 27 { 36 | return errors.New("February, more than 27") 37 | } 38 | } 39 | case 1, 3, 5, 7, 8, 10, 12: 40 | if input[2] > 31 { 41 | return errors.New("more than 31") 42 | } else { 43 | if input[2] > 30 { 44 | return errors.New("more than 30") 45 | } 46 | } 47 | } 48 | 49 | //时分秒 50 | if input[3] > 23 { 51 | return errors.New("hours more than 24") 52 | } 53 | 54 | if input[4] > 60 { 55 | return errors.New("minutes more than 60") 56 | } 57 | 58 | if input[5] > 60 { 59 | return errors.New("seconds more than 60") 60 | } 61 | 62 | return nil 63 | } 64 | 65 | func str2timeSecond(str string) (int, error) { 66 | //处理字符串 67 | now := time.Now().Unix() 68 | time_split := strings.Split(str, " ") //格式 2015-01-12 16:21:60 69 | date_ := strings.Split(time_split[0], "-") 70 | time_ := strings.Split(time_split[1], ":") 71 | //年月日 72 | if (len(date_) != 3) || (len(time_) != 3) { 73 | return 0, errors.New("input datetime string errors") 74 | } 75 | 76 | var time_int [6]int 77 | for i := 0; i < len(date_); i++ { 78 | time_int[i], _ = strconv.Atoi(date_[i]) 79 | } 80 | 81 | for j := 0; j < len(time_); j++ { 82 | time_int[j+3], _ = strconv.Atoi(time_[j]) 83 | } 84 | 85 | //基础查错 86 | err := findInputIsError(time_int) 87 | if err != nil { 88 | return 0, err 89 | } 90 | 91 | timestamp := time.Date(time_int[0], time.Month(time_int[1]), time_int[2], time_int[3], time_int[4], time_int[5], 0, time.Local).Unix() 92 | if timestamp < now { 93 | return 0, errors.New("input datatime less than now") 94 | } 95 | 96 | fmt.Println(timestamp, now) 97 | return (int)(timestamp - now), nil 98 | } 99 | 100 | func dofunc(i interface{}, f func()) (int, error) { 101 | var second_ = 0 102 | switch i.(type) { 103 | case int: 104 | second_ = i.(int) 105 | case int32: 106 | second_ = i.(int) 107 | case int64: 108 | second_ = i.(int) 109 | case string: 110 | var err error 111 | second_, err = str2timeSecond(i.(string)) 112 | if err != nil { 113 | return 0, err 114 | } 115 | default: 116 | } 117 | 118 | return second_, nil 119 | } 120 | 121 | func CreateTimer(i interface{}, isCycle bool, f func()) { //循环时间点 是否为循环 调用函数 122 | if isCycle { 123 | go func() { //定时循环开线程 124 | for { 125 | second, err := dofunc(i, f) 126 | if err != nil { 127 | fmt.Println(err) 128 | return 129 | } 130 | time.AfterFunc(time.Duration(time.Duration(second)*time.Second), f) //默认是秒 131 | time.Sleep(time.Duration(second) * time.Second) 132 | } 133 | }() 134 | } else { 135 | second, err := dofunc(i, f) 136 | if err != nil { 137 | fmt.Println(err) 138 | return 139 | } 140 | time.AfterFunc(time.Duration(time.Duration(second)*time.Second), f) //默认是秒 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /server/src/github.com/game_engine/timer/timer_test.go: -------------------------------------------------------------------------------- 1 | package timer 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | "time" 7 | ) 8 | 9 | func test() { 10 | fmt.Println("hello world") 11 | } 12 | 13 | func TestTimer(t *testing.T) { 14 | CreateTimer("-2015-10-20 10:20:10", false, test) 15 | CreateTimer("2015-10-32 13:20:10", false, test) 16 | CreateTimer("2000-02-30 10:20:10", false, test) 17 | CreateTimer("2015-04-31 10:20:10", false, test) 18 | CreateTimer("2015-10-20 25:20:10", false, test) 19 | CreateTimer("2015-10-20 23:61:10", false, test) 20 | CreateTimer("2015-10-20 13:23:45", false, test) 21 | 22 | CreateTimer(10, true, test) 23 | CreateTimer(10, false, test) 24 | time.Sleep(10000 * time.Second) 25 | } 26 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.[568ao] 3 | *.pb.go 4 | *.ao 5 | *.so 6 | *.pyc 7 | ._* 8 | .nfs.* 9 | [568a].out 10 | *~ 11 | *.orig 12 | core 13 | _obj 14 | _test 15 | _testmain.go 16 | compiler/protoc-gen-go 17 | compiler/testdata/extension_test 18 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at http://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at http://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/LICENSE: -------------------------------------------------------------------------------- 1 | Go support for Protocol Buffers - Google's data interchange format 2 | 3 | Copyright 2010 The Go Authors. All rights reserved. 4 | https://github.com/golang/protobuf 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above 13 | copyright notice, this list of conditions and the following disclaimer 14 | in the documentation and/or other materials provided with the 15 | distribution. 16 | * Neither the name of Google Inc. nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/Make.protobuf: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # https://github.com/golang/protobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | # Includable Makefile to add a rule for generating .pb.go files from .proto files 33 | # (Google protocol buffer descriptions). 34 | # Typical use if myproto.proto is a file in package mypackage in this directory: 35 | # 36 | # include $(GOROOT)/src/pkg/github.com/golang/protobuf/Make.protobuf 37 | 38 | %.pb.go: %.proto 39 | protoc --go_out=. $< 40 | 41 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # https://github.com/golang/protobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | 33 | all: install 34 | 35 | install: 36 | go install ./proto 37 | go install ./jsonpb 38 | go install ./protoc-gen-go 39 | 40 | test: 41 | go test ./proto 42 | go test ./jsonpb 43 | make -C protoc-gen-go/testdata test 44 | 45 | clean: 46 | go clean ./... 47 | 48 | nuke: 49 | go clean -i ./... 50 | 51 | regenerate: 52 | make -C protoc-gen-go/descriptor regenerate 53 | make -C protoc-gen-go/plugin regenerate 54 | make -C proto/testdata regenerate 55 | make -C jsonpb/jsonpb_test_proto regenerate 56 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/jsonpb/jsonpb_test_proto/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2015 The Go Authors. All rights reserved. 4 | # https://github.com/golang/protobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | regenerate: 33 | protoc --go_out=. *.proto 34 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/jsonpb/jsonpb_test_proto/more_test_objects.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2015 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | syntax = "proto3"; 33 | 34 | package jsonpb; 35 | 36 | message Simple3 { 37 | double dub = 1; 38 | } 39 | 40 | message Mappy { 41 | map nummy = 1; 42 | map strry = 2; 43 | map objjy = 3; 44 | map buggy = 4; 45 | map booly = 5; 46 | } 47 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/jsonpb/jsonpb_test_proto/test_objects.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2015 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | syntax = "proto2"; 33 | 34 | package jsonpb; 35 | 36 | // Test message for holding primitive types. 37 | message Simple { 38 | optional bool o_bool = 1; 39 | optional int32 o_int32 = 2; 40 | optional int64 o_int64 = 3; 41 | optional uint32 o_uint32 = 4; 42 | optional uint64 o_uint64 = 5; 43 | optional sint32 o_sint32 = 6; 44 | optional sint64 o_sint64 = 7; 45 | optional float o_float = 8; 46 | optional double o_double = 9; 47 | optional string o_string = 10; 48 | optional bytes o_bytes = 11; 49 | } 50 | 51 | // Test message for holding repeated primitives. 52 | message Repeats { 53 | repeated bool r_bool = 1; 54 | repeated int32 r_int32 = 2; 55 | repeated int64 r_int64 = 3; 56 | repeated uint32 r_uint32 = 4; 57 | repeated uint64 r_uint64 = 5; 58 | repeated sint32 r_sint32 = 6; 59 | repeated sint64 r_sint64 = 7; 60 | repeated float r_float = 8; 61 | repeated double r_double = 9; 62 | repeated string r_string = 10; 63 | repeated bytes r_bytes = 11; 64 | } 65 | 66 | // Test message for holding enums and nested messages. 67 | message Widget { 68 | enum Color { 69 | RED = 0; 70 | GREEN = 1; 71 | BLUE = 2; 72 | }; 73 | optional Color color = 1; 74 | repeated Color r_color = 2; 75 | 76 | optional Simple simple = 10; 77 | repeated Simple r_simple = 11; 78 | 79 | optional Repeats repeats = 20; 80 | repeated Repeats r_repeats = 21; 81 | } 82 | 83 | message Maps { 84 | map m_int64_str = 1; 85 | map m_bool_simple = 2; 86 | } 87 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/proto/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # https://github.com/golang/protobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | install: 33 | go install 34 | 35 | test: install generate-test-pbs 36 | go test 37 | 38 | 39 | generate-test-pbs: 40 | make install 41 | make -C testdata 42 | protoc --go_out=Mtestdata/test.proto=github.com/golang/protobuf/proto/testdata:. proto3_proto/proto3.proto 43 | make 44 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/proto/message_set_test.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2014 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | package proto 33 | 34 | import ( 35 | "bytes" 36 | "testing" 37 | ) 38 | 39 | func TestUnmarshalMessageSetWithDuplicate(t *testing.T) { 40 | // Check that a repeated message set entry will be concatenated. 41 | in := &MessageSet{ 42 | Item: []*_MessageSet_Item{ 43 | {TypeId: Int32(12345), Message: []byte("hoo")}, 44 | {TypeId: Int32(12345), Message: []byte("hah")}, 45 | }, 46 | } 47 | b, err := Marshal(in) 48 | if err != nil { 49 | t.Fatalf("Marshal: %v", err) 50 | } 51 | t.Logf("Marshaled bytes: %q", b) 52 | 53 | m := make(map[int32]Extension) 54 | if err := UnmarshalMessageSet(b, m); err != nil { 55 | t.Fatalf("UnmarshalMessageSet: %v", err) 56 | } 57 | ext, ok := m[12345] 58 | if !ok { 59 | t.Fatalf("Didn't retrieve extension 12345; map is %v", m) 60 | } 61 | // Skip wire type/field number and length varints. 62 | got := skipVarint(skipVarint(ext.enc)) 63 | if want := []byte("hoohah"); !bytes.Equal(got, want) { 64 | t.Errorf("Combined extension is %q, want %q", got, want) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/proto/proto3_proto/proto3.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2014 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | syntax = "proto3"; 33 | 34 | import "testdata/test.proto"; 35 | 36 | package proto3_proto; 37 | 38 | message Message { 39 | enum Humour { 40 | UNKNOWN = 0; 41 | PUNS = 1; 42 | SLAPSTICK = 2; 43 | BILL_BAILEY = 3; 44 | } 45 | 46 | string name = 1; 47 | Humour hilarity = 2; 48 | uint32 height_in_cm = 3; 49 | bytes data = 4; 50 | int64 result_count = 7; 51 | bool true_scotsman = 8; 52 | float score = 9; 53 | 54 | repeated uint64 key = 5; 55 | Nested nested = 6; 56 | 57 | map terrain = 10; 58 | testdata.SubDefaults proto2_field = 11; 59 | map proto2_value = 13; 60 | } 61 | 62 | message Nested { 63 | string bunny = 1; 64 | } 65 | 66 | message MessageWithMap { 67 | map byte_mapping = 1; 68 | } 69 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/proto/size2_test.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2012 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | package proto 33 | 34 | import ( 35 | "testing" 36 | ) 37 | 38 | // This is a separate file and package from size_test.go because that one uses 39 | // generated messages and thus may not be in package proto without having a circular 40 | // dependency, whereas this file tests unexported details of size.go. 41 | 42 | func TestVarintSize(t *testing.T) { 43 | // Check the edge cases carefully. 44 | testCases := []struct { 45 | n uint64 46 | size int 47 | }{ 48 | {0, 1}, 49 | {1, 1}, 50 | {127, 1}, 51 | {128, 2}, 52 | {16383, 2}, 53 | {16384, 3}, 54 | {1<<63 - 1, 9}, 55 | {1 << 63, 10}, 56 | } 57 | for _, tc := range testCases { 58 | size := sizeVarint(tc.n) 59 | if size != tc.size { 60 | t.Errorf("sizeVarint(%d) = %d, want %d", tc.n, size, tc.size) 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/proto/testdata/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # https://github.com/golang/protobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | 33 | include ../../Make.protobuf 34 | 35 | all: regenerate 36 | 37 | regenerate: 38 | rm -f test.pb.go 39 | make test.pb.go 40 | 41 | # The following rules are just aids to development. Not needed for typical testing. 42 | 43 | diff: regenerate 44 | git diff test.pb.go 45 | 46 | restore: 47 | cp test.pb.go.golden test.pb.go 48 | 49 | preserve: 50 | cp test.pb.go test.pb.go.golden 51 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/proto/testdata/golden_test.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2012 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | // Verify that the compiler output for test.proto is unchanged. 33 | 34 | package testdata 35 | 36 | import ( 37 | "crypto/sha1" 38 | "fmt" 39 | "io/ioutil" 40 | "os" 41 | "os/exec" 42 | "path/filepath" 43 | "testing" 44 | ) 45 | 46 | // sum returns in string form (for easy comparison) the SHA-1 hash of the named file. 47 | func sum(t *testing.T, name string) string { 48 | data, err := ioutil.ReadFile(name) 49 | if err != nil { 50 | t.Fatal(err) 51 | } 52 | t.Logf("sum(%q): length is %d", name, len(data)) 53 | hash := sha1.New() 54 | _, err = hash.Write(data) 55 | if err != nil { 56 | t.Fatal(err) 57 | } 58 | return fmt.Sprintf("% x", hash.Sum(nil)) 59 | } 60 | 61 | func run(t *testing.T, name string, args ...string) { 62 | cmd := exec.Command(name, args...) 63 | cmd.Stdin = os.Stdin 64 | cmd.Stdout = os.Stdout 65 | cmd.Stderr = os.Stderr 66 | err := cmd.Run() 67 | if err != nil { 68 | t.Fatal(err) 69 | } 70 | } 71 | 72 | func TestGolden(t *testing.T) { 73 | // Compute the original checksum. 74 | goldenSum := sum(t, "test.pb.go") 75 | // Run the proto compiler. 76 | run(t, "protoc", "--go_out="+os.TempDir(), "test.proto") 77 | newFile := filepath.Join(os.TempDir(), "test.pb.go") 78 | defer os.Remove(newFile) 79 | // Compute the new checksum. 80 | newSum := sum(t, newFile) 81 | // Verify 82 | if newSum != goldenSum { 83 | run(t, "diff", "-u", "test.pb.go", newFile) 84 | t.Fatal("Code generated by protoc-gen-go has changed; update test.pb.go") 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/Account.proto: -------------------------------------------------------------------------------- 1 | package protocol; 2 | 3 | 4 | message Account { 5 | 6 | //客户端消息 7 | //pid = 1 8 | message RegisterPlayer { 9 | optional string playername = 1; 10 | optional string passworld = 2; 11 | } 12 | 13 | //pid = 1 14 | message RegisterResult { 15 | optional int32 result = 1; 16 | } 17 | 18 | //pid = 2 19 | message LoginInfo{ 20 | optional string playername = 1; 21 | optional string passworld = 2; 22 | } 23 | 24 | //pid = 2 25 | message LoginResult { 26 | optional int32 result = 1; 27 | optional string gameserver = 2; 28 | optional int32 player_id = 3; 29 | } 30 | 31 | 32 | //发送给game消息 33 | 34 | //pid = 101 返回游戏服在线人数 35 | message GameResult { 36 | optional int32 count = 1; 37 | optional string game_address = 2; 38 | } 39 | 40 | //pid = 102 41 | message NoteGame { 42 | optional int32 player_id = 1; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/Game.proto: -------------------------------------------------------------------------------- 1 | package protocol; 2 | 3 | message Game { 4 | 5 | message BaseRole { 6 | required int32 player_id = 1;//玩家的id 账号服务器返回的 player id用来验证是否合法 7 | required string nick = 2;//角色昵称 8 | required int32 hero_id = 3;//所选英雄id 配置表验证 9 | } 10 | 11 | //pid = 1001 客户端发送注册角色信息 12 | message RegisterRole { 13 | optional BaseRole info = 1; 14 | } 15 | 16 | //pid = 1001 服务器返回 角色注册信息 17 | message RegisterRoleResult{ 18 | optional int32 result = 1; 19 | } 20 | 21 | //pid = 1002 获取角色信息 22 | message GetRoleInfo{ 23 | } 24 | 25 | 26 | message Attribute { //属性 27 | optional int32 level = 1;//等级 28 | optional int32 exp = 3;//经验 29 | optional int32 hp = 2;//血量 30 | 31 | repeated int32 physical_def = 4;//物理防御(升级 ,强化,精炼) 32 | repeated int32 magic_def = 5;//法术防御 33 | repeated int32 physical_damage = 6;//物理伤害 34 | repeated int32 magic_damage= 7;//法术伤害 35 | } 36 | 37 | message HangUpInfo { //挂机相关 38 | optional int32 type = 1;//(1:道具 2:英雄 3:装备 4:资源) 39 | optional int32 id = 2;//对应物品id 40 | optional int32 count = 3;//数量 41 | } 42 | 43 | //pid = 1002 角色返回 44 | message RoleInfoResult { 45 | optional BaseRole base_role = 1; 46 | optional Attribute attribute = 2; 47 | repeated HangUpInfo hang_up_info = 3; 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # https://github.com/golang/protobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | test: 33 | cd testdata && make test 34 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/c++ proto.bat: -------------------------------------------------------------------------------- 1 | d: 2 | cd D:\hujunlong\Server4Go\src\github.com\golang\protobuf\protoc-gen-go 3 | protoc --cpp_out=. protocol.proto -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/copy_C++.bat: -------------------------------------------------------------------------------- 1 | del /q D:\goTest\src\server\protocol\protocol.pb.cc 2 | del /q D:\goTest\src\server\protocol\protocol.pb.h 3 | 4 | copy D:\hujunlong\Server4Go\src\github.com\golang\protobuf\protoc-gen-go\protocol.pb.cc D:\game\Classes 5 | copy D:\hujunlong\Server4Go\src\github.com\golang\protobuf\protoc-gen-go\protocol.pb.h D:\game\Classes -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/copy_go.bat: -------------------------------------------------------------------------------- 1 | del /q D:\book\guaji_server\server\src\server\share\protocol\protocol.pb.go 2 | copy D:\book\guaji_server\server\src\github.com\golang\protobuf\protoc-gen-go\Account.pb.go D:\book\guaji_server\server\src\server\share\protocol 3 | copy D:\book\guaji_server\server\src\github.com\golang\protobuf\protoc-gen-go\Game.pb.go D:\book\guaji_server\server\src\server\share\protocol -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/descriptor/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # https://github.com/golang/protobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | # Not stored here, but descriptor.proto is in https://github.com/google/protobuf/ 33 | # at src/google/protobuf/descriptor.proto 34 | regenerate: 35 | echo WARNING! THIS RULE IS PROBABLY NOT RIGHT FOR YOUR INSTALLATION 36 | cd $(HOME)/src/protobuf/src && \ 37 | protoc --go_out=. ./google/protobuf/descriptor.proto && \ 38 | sed -i 's,^package google_protobuf,package descriptor,' google/protobuf/descriptor.pb.go && \ 39 | cp ./google/protobuf/descriptor.pb.go $(GOPATH)/src/github.com/golang/protobuf/protoc-gen-go/descriptor/descriptor.pb.go 40 | 41 | restore: 42 | cp descriptor.pb.golden descriptor.pb.go 43 | 44 | preserve: 45 | cp descriptor.pb.go descriptor.pb.golden 46 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/doc.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2010 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | /* 33 | A plugin for the Google protocol buffer compiler to generate Go code. 34 | Run it by building this program and putting it in your path with the name 35 | protoc-gen-go 36 | That word 'go' at the end becomes part of the option string set for the 37 | protocol compiler, so once the protocol compiler (protoc) is installed 38 | you can run 39 | protoc --go_out=output_directory input_directory/file.proto 40 | to generate Go bindings for the protocol defined by file.proto. 41 | With that input, the output will be written to 42 | output_directory/file.pb.go 43 | 44 | The generated code is documented in the package comment for 45 | the library. 46 | 47 | See the README and documentation for protocol buffers to learn more: 48 | https://developers.google.com/protocol-buffers/ 49 | 50 | */ 51 | package documentation 52 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/generator/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # https://github.com/golang/protobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | include $(GOROOT)/src/Make.inc 33 | 34 | TARG=github.com/golang/protobuf/compiler/generator 35 | GOFILES=\ 36 | generator.go\ 37 | 38 | DEPS=../descriptor ../plugin ../../proto 39 | 40 | include $(GOROOT)/src/Make.pkg 41 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/generator/name_test.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2013 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | package generator 33 | 34 | import ( 35 | "testing" 36 | ) 37 | 38 | func TestCamelCase(t *testing.T) { 39 | tests := []struct { 40 | in, want string 41 | }{ 42 | {"one", "One"}, 43 | {"one_two", "OneTwo"}, 44 | {"_my_field_name_2", "XMyFieldName_2"}, 45 | {"Something_Capped", "Something_Capped"}, 46 | {"my_Name", "My_Name"}, 47 | {"OneTwo", "OneTwo"}, 48 | {"_", "X"}, 49 | {"_a_", "XA_"}, 50 | } 51 | for _, tc := range tests { 52 | if got := CamelCase(tc.in); got != tc.want { 53 | t.Errorf("CamelCase(%q) = %q, want %q", tc.in, got, tc.want) 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/go proto.bat: -------------------------------------------------------------------------------- 1 | d: 2 | cd D:\book\guaji_server\server\src\github.com\golang\protobuf\protoc-gen-go 3 | protoc --go_out=. Account.proto 4 | protoc --go_out=. Game.proto -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/link_grpc.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2015 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | package main 33 | 34 | import _ "github.com/golang/protobuf/protoc-gen-go/internal/grpc" 35 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/main.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2010 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | // protoc-gen-go is a plugin for the Google protocol buffer compiler to generate 33 | // Go code. Run it by building this program and putting it in your path with 34 | // the name 35 | // protoc-gen-go 36 | // That word 'go' at the end becomes part of the option string set for the 37 | // protocol compiler, so once the protocol compiler (protoc) is installed 38 | // you can run 39 | // protoc --go_out=output_directory input_directory/file.proto 40 | // to generate Go bindings for the protocol defined by file.proto. 41 | // With that input, the output will be written to 42 | // output_directory/file.pb.go 43 | // 44 | // The generated code is documented in the package comment for 45 | // the library. 46 | // 47 | // See the README and documentation for protocol buffers to learn more: 48 | // https://developers.google.com/protocol-buffers/ 49 | package main 50 | 51 | import ( 52 | "io/ioutil" 53 | "os" 54 | 55 | "github.com/golang/protobuf/proto" 56 | "github.com/golang/protobuf/protoc-gen-go/generator" 57 | ) 58 | 59 | func main() { 60 | // Begin by allocating a generator. The request and response structures are stored there 61 | // so we can do error handling easily - the response structure contains the field to 62 | // report failure. 63 | g := generator.New() 64 | 65 | data, err := ioutil.ReadAll(os.Stdin) 66 | if err != nil { 67 | g.Error(err, "reading input") 68 | } 69 | 70 | if err := proto.Unmarshal(data, g.Request); err != nil { 71 | g.Error(err, "parsing input proto") 72 | } 73 | 74 | if len(g.Request.FileToGenerate) == 0 { 75 | g.Fail("no files to generate") 76 | } 77 | 78 | g.CommandLineParameters(g.Request.GetParameter()) 79 | 80 | // Create a wrapped version of the Descriptors and EnumDescriptors that 81 | // point to the file that defines them. 82 | g.WrapTypes() 83 | 84 | g.SetPackageNames() 85 | g.BuildTypeNameMap() 86 | 87 | g.GenerateAllFiles() 88 | 89 | // Send back the results. 90 | data, err = proto.Marshal(g.Response) 91 | if err != nil { 92 | g.Error(err, "failed to marshal output proto") 93 | } 94 | _, err = os.Stdout.Write(data) 95 | if err != nil { 96 | g.Error(err, "failed to write output proto") 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/plugin/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # https://github.com/golang/protobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | # Not stored here, but plugin.proto is in https://github.com/google/protobuf/ 33 | # at src/google/protobuf/compiler/plugin.proto 34 | # Also we need to fix an import. 35 | regenerate: 36 | echo WARNING! THIS RULE IS PROBABLY NOT RIGHT FOR YOUR INSTALLATION 37 | cd $(HOME)/src/protobuf/src && \ 38 | protoc --go_out=Mgoogle/protobuf/descriptor.proto=github.com/golang/protobuf/protoc-gen-go/descriptor:. \ 39 | ./google/protobuf/compiler/plugin.proto && \ 40 | cat ./google/protobuf/compiler/plugin.pb.go > $(GOPATH)/src/github.com/golang/protobuf/protoc-gen-go/plugin/plugin.pb.go 41 | 42 | restore: 43 | cp plugin.pb.golden plugin.pb.go 44 | 45 | preserve: 46 | cp plugin.pb.go plugin.pb.golden 47 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/plugin/plugin.pb.golden: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. 2 | // source: google/protobuf/compiler/plugin.proto 3 | // DO NOT EDIT! 4 | 5 | package google_protobuf_compiler 6 | 7 | import proto "github.com/golang/protobuf/proto" 8 | import "math" 9 | import google_protobuf "github.com/golang/protobuf/protoc-gen-go/descriptor" 10 | 11 | // Reference proto and math imports to suppress error if they are not otherwise used. 12 | var _ = proto.GetString 13 | var _ = math.Inf 14 | 15 | type CodeGeneratorRequest struct { 16 | FileToGenerate []string `protobuf:"bytes,1,rep,name=file_to_generate" json:"file_to_generate,omitempty"` 17 | Parameter *string `protobuf:"bytes,2,opt,name=parameter" json:"parameter,omitempty"` 18 | ProtoFile []*google_protobuf.FileDescriptorProto `protobuf:"bytes,15,rep,name=proto_file" json:"proto_file,omitempty"` 19 | XXX_unrecognized []byte `json:"-"` 20 | } 21 | 22 | func (this *CodeGeneratorRequest) Reset() { *this = CodeGeneratorRequest{} } 23 | func (this *CodeGeneratorRequest) String() string { return proto.CompactTextString(this) } 24 | func (*CodeGeneratorRequest) ProtoMessage() {} 25 | 26 | func (this *CodeGeneratorRequest) GetParameter() string { 27 | if this != nil && this.Parameter != nil { 28 | return *this.Parameter 29 | } 30 | return "" 31 | } 32 | 33 | type CodeGeneratorResponse struct { 34 | Error *string `protobuf:"bytes,1,opt,name=error" json:"error,omitempty"` 35 | File []*CodeGeneratorResponse_File `protobuf:"bytes,15,rep,name=file" json:"file,omitempty"` 36 | XXX_unrecognized []byte `json:"-"` 37 | } 38 | 39 | func (this *CodeGeneratorResponse) Reset() { *this = CodeGeneratorResponse{} } 40 | func (this *CodeGeneratorResponse) String() string { return proto.CompactTextString(this) } 41 | func (*CodeGeneratorResponse) ProtoMessage() {} 42 | 43 | func (this *CodeGeneratorResponse) GetError() string { 44 | if this != nil && this.Error != nil { 45 | return *this.Error 46 | } 47 | return "" 48 | } 49 | 50 | type CodeGeneratorResponse_File struct { 51 | Name *string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` 52 | InsertionPoint *string `protobuf:"bytes,2,opt,name=insertion_point" json:"insertion_point,omitempty"` 53 | Content *string `protobuf:"bytes,15,opt,name=content" json:"content,omitempty"` 54 | XXX_unrecognized []byte `json:"-"` 55 | } 56 | 57 | func (this *CodeGeneratorResponse_File) Reset() { *this = CodeGeneratorResponse_File{} } 58 | func (this *CodeGeneratorResponse_File) String() string { return proto.CompactTextString(this) } 59 | func (*CodeGeneratorResponse_File) ProtoMessage() {} 60 | 61 | func (this *CodeGeneratorResponse_File) GetName() string { 62 | if this != nil && this.Name != nil { 63 | return *this.Name 64 | } 65 | return "" 66 | } 67 | 68 | func (this *CodeGeneratorResponse_File) GetInsertionPoint() string { 69 | if this != nil && this.InsertionPoint != nil { 70 | return *this.InsertionPoint 71 | } 72 | return "" 73 | } 74 | 75 | func (this *CodeGeneratorResponse_File) GetContent() string { 76 | if this != nil && this.Content != nil { 77 | return *this.Content 78 | } 79 | return "" 80 | } 81 | 82 | func init() { 83 | } 84 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/protoc-gen-go.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/src/github.com/golang/protobuf/protoc-gen-go/protoc-gen-go.exe -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/protoc.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/src/github.com/golang/protobuf/protoc-gen-go/protoc.exe -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/testdata/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # https://github.com/golang/protobuf 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | all: 33 | @echo run make test 34 | 35 | include ../../Make.protobuf 36 | 37 | test: golden testbuild 38 | 39 | #test: golden testbuild extension_test 40 | # ./extension_test 41 | # @echo PASS 42 | 43 | golden: 44 | make -B my_test/test.pb.go 45 | diff -w my_test/test.pb.go my_test/test.pb.go.golden 46 | 47 | nuke: clean 48 | 49 | testbuild: buildprotos 50 | go test 51 | 52 | buildprotos: 53 | # Invoke protoc once to generate three independent .pb.go files in the same package. 54 | protoc --go_out=. multi/multi{1,2,3}.proto 55 | 56 | #extension_test: extension_test.$O 57 | # $(LD) -L. -o $@ $< 58 | 59 | #multi.a: multi3.pb.$O multi2.pb.$O multi1.pb.$O 60 | # rm -f multi.a 61 | # $(QUOTED_GOBIN)/gopack grc $@ $< 62 | 63 | #test.pb.go: imp.pb.go 64 | #multi1.pb.go: multi2.pb.go multi3.pb.go 65 | #main.$O: imp.pb.$O test.pb.$O multi.a 66 | #extension_test.$O: extension_base.pb.$O extension_extra.pb.$O extension_user.pb.$O 67 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/testdata/extension_base.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2010 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | syntax = "proto2"; 33 | 34 | package extension_base; 35 | 36 | message BaseMessage { 37 | optional int32 height = 1; 38 | extensions 4 to 9; 39 | extensions 16 to max; 40 | } 41 | 42 | // Another message that may be extended, using message_set_wire_format. 43 | message OldStyleMessage { 44 | option message_set_wire_format = true; 45 | extensions 100 to max; 46 | } 47 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/testdata/extension_extra.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2011 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | syntax = "proto2"; 33 | 34 | package extension_extra; 35 | 36 | message ExtraMessage { 37 | optional int32 width = 1; 38 | } 39 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/testdata/extension_user.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2010 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | syntax = "proto2"; 33 | 34 | import "extension_base.proto"; 35 | import "extension_extra.proto"; 36 | 37 | package extension_user; 38 | 39 | message UserMessage { 40 | optional string name = 1; 41 | optional string rank = 2; 42 | } 43 | 44 | // Extend with a message 45 | extend extension_base.BaseMessage { 46 | optional UserMessage user_message = 5; 47 | } 48 | 49 | // Extend with a foreign message 50 | extend extension_base.BaseMessage { 51 | optional extension_extra.ExtraMessage extra_message = 9; 52 | } 53 | 54 | // Extend with some primitive types 55 | extend extension_base.BaseMessage { 56 | optional int32 width = 6; 57 | optional int64 area = 7; 58 | } 59 | 60 | // Extend inside the scope of another type 61 | message LoudMessage { 62 | extend extension_base.BaseMessage { 63 | optional uint32 volume = 8; 64 | } 65 | extensions 100 to max; 66 | } 67 | 68 | // Extend inside the scope of another type, using a message. 69 | message LoginMessage { 70 | extend extension_base.BaseMessage { 71 | optional UserMessage user_message = 16; 72 | } 73 | } 74 | 75 | // Extend with a repeated field 76 | extend extension_base.BaseMessage { 77 | repeated Detail detail = 17; 78 | } 79 | 80 | message Detail { 81 | optional string color = 1; 82 | } 83 | 84 | // An extension of an extension 85 | message Announcement { 86 | optional string words = 1; 87 | extend LoudMessage { 88 | optional Announcement loud_ext = 100; 89 | } 90 | } 91 | 92 | // Something that can be put in a message set. 93 | message OldStyleParcel { 94 | extend extension_base.OldStyleMessage { 95 | optional OldStyleParcel message_set_extension = 2001; 96 | } 97 | 98 | required string name = 1; 99 | optional int32 height = 2; 100 | } 101 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/testdata/golden_test.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2012 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | // Verify that the compiler output for test.proto is unchanged. 33 | 34 | package testdata 35 | 36 | import ( 37 | "crypto/sha1" 38 | "fmt" 39 | "io/ioutil" 40 | "os" 41 | "os/exec" 42 | "path/filepath" 43 | "testing" 44 | ) 45 | 46 | // sum returns in string form (for easy comparison) the SHA-1 hash of the named file. 47 | func sum(t *testing.T, name string) string { 48 | data, err := ioutil.ReadFile(name) 49 | if err != nil { 50 | t.Fatal(err) 51 | } 52 | t.Logf("sum(%q): length is %d", name, len(data)) 53 | hash := sha1.New() 54 | _, err = hash.Write(data) 55 | if err != nil { 56 | t.Fatal(err) 57 | } 58 | return fmt.Sprintf("% x", hash.Sum(nil)) 59 | } 60 | 61 | func run(t *testing.T, name string, args ...string) { 62 | cmd := exec.Command(name, args...) 63 | cmd.Stdin = os.Stdin 64 | cmd.Stdout = os.Stdout 65 | cmd.Stderr = os.Stderr 66 | err := cmd.Run() 67 | if err != nil { 68 | t.Fatal(err) 69 | } 70 | } 71 | 72 | func TestGolden(t *testing.T) { 73 | // Compute the original checksum. 74 | goldenSum := sum(t, "my_test/test.pb.go") 75 | // Run the proto compiler. 76 | run(t, "protoc", "--go_out="+os.TempDir(), "my_test/test.proto") 77 | newFile := filepath.Join(os.TempDir(), "my_test/test.pb.go") 78 | defer os.Remove(newFile) 79 | // Compute the new checksum. 80 | newSum := sum(t, newFile) 81 | // Verify 82 | if newSum != goldenSum { 83 | run(t, "diff", "-u", "my_test/test.pb.go", newFile) 84 | t.Fatal("Code generated by protoc-gen-go has changed; update test.pb.go") 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/testdata/grpc.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2015 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | syntax = "proto3"; 33 | 34 | package grpc.testing; 35 | 36 | message SimpleRequest { 37 | } 38 | 39 | message SimpleResponse { 40 | } 41 | 42 | message StreamMsg { 43 | } 44 | 45 | message StreamMsg2 { 46 | } 47 | 48 | service Test { 49 | rpc UnaryCall(SimpleRequest) returns (SimpleResponse); 50 | 51 | // This RPC streams from the server only. 52 | rpc Downstream(SimpleRequest) returns (stream StreamMsg); 53 | 54 | // This RPC streams from the client. 55 | rpc Upstream(stream StreamMsg) returns (SimpleResponse); 56 | 57 | // This one streams in both directions. 58 | rpc Bidi(stream StreamMsg) returns (stream StreamMsg2); 59 | } 60 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/testdata/imp.pb.go.golden: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. 2 | // source: imp.proto 3 | // DO NOT EDIT! 4 | 5 | package imp 6 | 7 | import proto "github.com/golang/protobuf/proto" 8 | import "math" 9 | import "os" 10 | import imp1 "imp2.pb" 11 | 12 | // Reference proto & math imports to suppress error if they are not otherwise used. 13 | var _ = proto.GetString 14 | var _ = math.Inf 15 | 16 | // Types from public import imp2.proto 17 | type PubliclyImportedMessage imp1.PubliclyImportedMessage 18 | 19 | func (this *PubliclyImportedMessage) Reset() { (*imp1.PubliclyImportedMessage)(this).Reset() } 20 | func (this *PubliclyImportedMessage) String() string { 21 | return (*imp1.PubliclyImportedMessage)(this).String() 22 | } 23 | 24 | // PubliclyImportedMessage from public import imp.proto 25 | 26 | type ImportedMessage_Owner int32 27 | 28 | const ( 29 | ImportedMessage_DAVE ImportedMessage_Owner = 1 30 | ImportedMessage_MIKE ImportedMessage_Owner = 2 31 | ) 32 | 33 | var ImportedMessage_Owner_name = map[int32]string{ 34 | 1: "DAVE", 35 | 2: "MIKE", 36 | } 37 | var ImportedMessage_Owner_value = map[string]int32{ 38 | "DAVE": 1, 39 | "MIKE": 2, 40 | } 41 | 42 | // NewImportedMessage_Owner is deprecated. Use x.Enum() instead. 43 | func NewImportedMessage_Owner(x ImportedMessage_Owner) *ImportedMessage_Owner { 44 | e := ImportedMessage_Owner(x) 45 | return &e 46 | } 47 | func (x ImportedMessage_Owner) Enum() *ImportedMessage_Owner { 48 | p := new(ImportedMessage_Owner) 49 | *p = x 50 | return p 51 | } 52 | func (x ImportedMessage_Owner) String() string { 53 | return proto.EnumName(ImportedMessage_Owner_name, int32(x)) 54 | } 55 | 56 | type ImportedMessage struct { 57 | Field *int64 `protobuf:"varint,1,req,name=field" json:"field,omitempty"` 58 | XXX_extensions map[int32][]byte `json:",omitempty"` 59 | XXX_unrecognized []byte `json:",omitempty"` 60 | } 61 | 62 | func (this *ImportedMessage) Reset() { *this = ImportedMessage{} } 63 | func (this *ImportedMessage) String() string { return proto.CompactTextString(this) } 64 | 65 | var extRange_ImportedMessage = []proto.ExtensionRange{ 66 | proto.ExtensionRange{90, 100}, 67 | } 68 | 69 | func (*ImportedMessage) ExtensionRangeArray() []proto.ExtensionRange { 70 | return extRange_ImportedMessage 71 | } 72 | func (this *ImportedMessage) ExtensionMap() map[int32][]byte { 73 | if this.XXX_extensions == nil { 74 | this.XXX_extensions = make(map[int32][]byte) 75 | } 76 | return this.XXX_extensions 77 | } 78 | 79 | type ImportedExtendable struct { 80 | XXX_extensions map[int32][]byte `json:",omitempty"` 81 | XXX_unrecognized []byte `json:",omitempty"` 82 | } 83 | 84 | func (this *ImportedExtendable) Reset() { *this = ImportedExtendable{} } 85 | func (this *ImportedExtendable) String() string { return proto.CompactTextString(this) } 86 | 87 | func (this *ImportedExtendable) Marshal() ([]byte, error) { 88 | return proto.MarshalMessageSet(this.ExtensionMap()) 89 | } 90 | func (this *ImportedExtendable) Unmarshal(buf []byte) error { 91 | return proto.UnmarshalMessageSet(buf, this.ExtensionMap()) 92 | } 93 | // ensure ImportedExtendable satisfies proto.Marshaler and proto.Unmarshaler 94 | var _ proto.Marshaler = (*ImportedExtendable)(nil) 95 | var _ proto.Unmarshaler = (*ImportedExtendable)(nil) 96 | 97 | var extRange_ImportedExtendable = []proto.ExtensionRange{ 98 | proto.ExtensionRange{100, 536870911}, 99 | } 100 | 101 | func (*ImportedExtendable) ExtensionRangeArray() []proto.ExtensionRange { 102 | return extRange_ImportedExtendable 103 | } 104 | func (this *ImportedExtendable) ExtensionMap() map[int32][]byte { 105 | if this.XXX_extensions == nil { 106 | this.XXX_extensions = make(map[int32][]byte) 107 | } 108 | return this.XXX_extensions 109 | } 110 | 111 | func init() { 112 | proto.RegisterEnum("imp.ImportedMessage_Owner", ImportedMessage_Owner_name, ImportedMessage_Owner_value) 113 | } 114 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/testdata/imp.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2010 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | syntax = "proto2"; 33 | 34 | package imp; 35 | 36 | import "imp2.proto"; 37 | import "imp3.proto"; 38 | 39 | message ImportedMessage { 40 | required int64 field = 1; 41 | 42 | // The forwarded getters for these fields are fiddly to get right. 43 | optional ImportedMessage2 local_msg = 2; 44 | optional ForeignImportedMessage foreign_msg = 3; // in imp3.proto 45 | optional Owner enum_field = 4; 46 | 47 | repeated string name = 5; 48 | repeated Owner boss = 6; 49 | repeated ImportedMessage2 memo = 7; 50 | 51 | enum Owner { 52 | DAVE = 1; 53 | MIKE = 2; 54 | } 55 | 56 | extensions 90 to 100; 57 | } 58 | 59 | message ImportedMessage2 { 60 | } 61 | 62 | message ImportedExtendable { 63 | option message_set_wire_format = true; 64 | extensions 100 to max; 65 | } 66 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/testdata/imp2.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2011 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | syntax = "proto2"; 33 | 34 | package imp; 35 | 36 | message PubliclyImportedMessage { 37 | optional int64 field = 1; 38 | } 39 | 40 | enum PubliclyImportedEnum { 41 | GLASSES = 1; 42 | HAIR = 2; 43 | } 44 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/testdata/imp3.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2012 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | syntax = "proto2"; 33 | 34 | package imp; 35 | 36 | message ForeignImportedMessage { 37 | optional string tuber = 1; 38 | } 39 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/testdata/main_test.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2010 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | // A simple binary to link together the protocol buffers in this test. 33 | 34 | package testdata 35 | 36 | import ( 37 | "testing" 38 | 39 | multipb "./multi" 40 | mytestpb "./my_test" 41 | ) 42 | 43 | func TestLink(t *testing.T) { 44 | _ = &multipb.Multi1{} 45 | _ = &mytestpb.Request{} 46 | } 47 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/testdata/multi/multi1.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2010 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | syntax = "proto2"; 33 | 34 | import "multi/multi2.proto"; 35 | import "multi/multi3.proto"; 36 | 37 | package multitest; 38 | 39 | message Multi1 { 40 | required Multi2 multi2 = 1; 41 | optional Multi2.Color color = 2; 42 | optional Multi3.HatType hat_type = 3; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/testdata/multi/multi2.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2010 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | syntax = "proto2"; 33 | 34 | package multitest; 35 | 36 | message Multi2 { 37 | required int32 required_value = 1; 38 | 39 | enum Color { 40 | BLUE = 1; 41 | GREEN = 2; 42 | RED = 3; 43 | }; 44 | optional Color color = 2; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/testdata/multi/multi3.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2010 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | syntax = "proto2"; 33 | 34 | package multitest; 35 | 36 | message Multi3 { 37 | enum HatType { 38 | FEDORA = 1; 39 | FEZ = 2; 40 | }; 41 | optional HatType hat_type = 1; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /server/src/github.com/golang/protobuf/protoc-gen-go/testdata/proto3.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2014 The Go Authors. All rights reserved. 4 | // https://github.com/golang/protobuf 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | syntax = "proto3"; 33 | 34 | package proto3; 35 | 36 | message Request { 37 | enum Flavour { 38 | SWEET = 0; 39 | SOUR = 1; 40 | UMAMI = 2; 41 | GOPHERLICIOUS = 3; 42 | } 43 | string name = 1; 44 | repeated int64 key = 2; 45 | Flavour taste = 3; 46 | Book book = 4; 47 | } 48 | 49 | message Book { 50 | string title = 1; 51 | bytes raw_data = 2; 52 | } 53 | -------------------------------------------------------------------------------- /server/src/server/gameServer/deal2a.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "net" 5 | "server/gameServer/game" 6 | "server/share/protocol" 7 | "strconv" 8 | "sync" 9 | 10 | "fmt" 11 | 12 | "github.com/game_engine/cache/redis" 13 | "github.com/golang/protobuf/proto" 14 | ) 15 | 16 | type Deal2A struct { 17 | server_note_address string //通知玩家需要登录的游戏服 18 | server_count int32 //在线人数 19 | server_id int32 //游戏服id 20 | deal2amx *sync.RWMutex 21 | } 22 | 23 | func (this *Deal2A) Init() { 24 | this.deal2amx = new(sync.RWMutex) 25 | this.server_note_address = sys_config.ServerNoteAddress 26 | this.server_count = 0 27 | this.server_id = sys_config.GameId 28 | 29 | fmt.Println("this.server_note_address =", this.server_note_address, "this.server_id=", this.server_id) 30 | } 31 | 32 | func (this *Deal2A) send2AccountMenber() { 33 | this.server_count += 1 34 | result2A := &protocol.Account_GameResult{ 35 | Count: proto.Int32(this.server_count), 36 | GameAddress: proto.String(this.server_note_address), 37 | } 38 | 39 | encObj, _ := proto.Marshal(result2A) 40 | SendPackage(conn2a, 101, encObj) 41 | 42 | } 43 | 44 | func (this *Deal2A) Task(pid int32, buf []byte, n int) { 45 | switch pid { 46 | case 102: //账号服务器登陆成功后往 game服务器写入 playerid sn 47 | get_note := new(protocol.Account_NoteGame) 48 | if err := proto.Unmarshal(buf[0:n], get_note); err == nil { 49 | player_id := get_note.GetPlayerId() 50 | game.Log.Info("player_id = %d", player_id) 51 | this.NoteGame(player_id) 52 | } 53 | 54 | default: 55 | } 56 | } 57 | 58 | //防外挂 逻辑更严密 59 | func (this *Deal2A) NoteGame(player_id int32) { 60 | this.deal2amx.Lock() 61 | defer this.deal2amx.Unlock() 62 | 63 | id := this.server_id + player_id 64 | 65 | key := "role:" + strconv.Itoa(int(id)) 66 | is_exists, _ := redis.Exists(key) 67 | 68 | if !is_exists { 69 | redis.Add(key, "") 70 | } 71 | } 72 | 73 | //账号服务器通知game服务器 消息下发 74 | func (this *Deal2A) Handler2A(conn net.Conn) { 75 | defer conn.Close() 76 | const MAXLEN = 1024 77 | buf := make([]byte, MAXLEN) 78 | for { 79 | n, err := conn.Read(buf) //接收具体消息 80 | if err != nil { 81 | return 82 | } 83 | 84 | if n > MAXLEN { 85 | game.Log.Error("recive error n> MAXLEN") 86 | return 87 | } 88 | 89 | //接收包头 90 | _, head_pid := GetHead(buf) 91 | go this.Task(head_pid, buf[8:], n-8) 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /server/src/server/gameServer/deal4c.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "server/gameServer/game" 7 | "server/share/global" 8 | "server/share/protocol" 9 | "strconv" 10 | 11 | "github.com/golang/protobuf/proto" 12 | ) 13 | 14 | var sys_config *game.SysConfig //系统配置 15 | 16 | type Deal4C struct { 17 | server_id int32 18 | players map[string]*game.Player //在线玩家指针 map 19 | 20 | } 21 | 22 | func (this *Deal4C) Init() { 23 | sys_config = new(game.SysConfig) 24 | sys_config.Init() 25 | 26 | this.server_id = sys_config.GameId 27 | this.players = make(map[string]*game.Player) 28 | } 29 | 30 | func (this *Deal4C) Deal4Client(listener net.Listener) { 31 | for { 32 | conn, err := listener.Accept() 33 | if CheckError(err) { 34 | go this.Handler4C(conn) 35 | } 36 | } 37 | } 38 | 39 | func (this *Deal4C) Handler4C(conn net.Conn) { 40 | defer conn.Close() 41 | 42 | var player *game.Player //玩家对象的指针 43 | 44 | const MAXLEN = 1024 45 | buf := make([]byte, MAXLEN) 46 | for { 47 | 48 | n, err := conn.Read(buf) //接收具体消息 49 | if err != nil { 50 | return 51 | } 52 | 53 | if n > MAXLEN { 54 | game.Log.Error("recive error n> MAXLEN") 55 | return 56 | } 57 | 58 | fmt.Println(buf[0:n]) 59 | 60 | //接收包头 61 | _, head_pid := GetHead(buf) 62 | //包体 63 | switch head_pid { 64 | case 1001: //注册 65 | register := new(protocol.Game_RegisterRole) 66 | if err := proto.Unmarshal(buf[8:n], register); err == nil { 67 | player = new(game.Player) 68 | player.Init(&conn) 69 | sn := this.server_id + register.Info.GetPlayerId() 70 | 71 | fmt.Println(register.Info.GetPlayerId(), this.server_id, register.Info.GetNick(), register.Info.GetHeroId()) 72 | result := player.RegisterRole(sn, register.Info.GetPlayerId(), this.server_id, register.Info.GetNick(), register.Info.GetHeroId()) 73 | 74 | result4C := &protocol.Game_RegisterRoleResult{ 75 | Result: proto.Int32(result), 76 | } 77 | encObj, _ := proto.Marshal(result4C) 78 | SendPackage(conn, 1001, encObj) 79 | //加载保存于内存中 80 | if global.REGISTERROLESUCCESS == result { 81 | key := strconv.Itoa(int(sn)) 82 | this.players[key] = player 83 | } 84 | } 85 | 86 | case 1002: //获取role基础属性 87 | 88 | fmt.Println("come role base") 89 | var pid int32 = 123 90 | var nick string = "afds" 91 | var hero_id int32 = 12 92 | //var level int32 = 1 93 | var exp int32 = 0 94 | var hp int32 = 70 95 | physical_def := []int32{2, 4} 96 | magic_def := []int32{2, 4} 97 | physical_damage := []int32{2, 4} 98 | magic_damage := []int32{2, 4} 99 | 100 | result4C := &protocol.Game_RoleInfoResult{ 101 | 102 | BaseRole: &protocol.Game_BaseRole{ 103 | PlayerId: &pid, 104 | Nick: &nick, 105 | HeroId: &hero_id, 106 | }, 107 | 108 | Attribute: &protocol.Game_Attribute{ 109 | Exp: &exp, 110 | Hp: &hp, 111 | PhysicalDef: physical_def, 112 | MagicDef: magic_def, 113 | PhysicalDamage: physical_damage, 114 | MagicDamage: magic_damage, 115 | }, 116 | } 117 | 118 | encObj, _ := proto.Marshal(result4C) 119 | fmt.Println(encObj) 120 | SendPackage(conn, 1002, encObj) 121 | 122 | default: 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /server/src/server/gameServer/game/csvConfig.go: -------------------------------------------------------------------------------- 1 | //读取策划配置 2 | package game 3 | 4 | import ( 5 | "encoding/csv" 6 | "fmt" 7 | "os" 8 | ) 9 | 10 | type CsvConfig struct { 11 | Create_role map[string][]string 12 | Role map[string][]string 13 | Drop_stage map[string][][]string 14 | } 15 | 16 | func readConfig(path string, key_index int) map[string][]string { 17 | 18 | rfile, _ := os.Open(path) 19 | r := csv.NewReader(rfile) 20 | strs, err := r.ReadAll() 21 | 22 | if err != nil { 23 | fmt.Println("err:", err) 24 | return nil 25 | } 26 | 27 | //检测数据是否存在合法 28 | if len(strs) < 0 || len(strs[0]) < key_index { 29 | return nil 30 | } 31 | 32 | buf_map := make(map[string][]string) 33 | 34 | for _, v := range strs { 35 | key := v[key_index] 36 | buf_map[key] = v 37 | } 38 | return buf_map 39 | } 40 | 41 | func (this *CsvConfig) Init() { 42 | 43 | this.Create_role = make(map[string][]string) 44 | this.Role = make(map[string][]string) 45 | 46 | this.Create_role = readConfig("config/csv/creat_role.csv", 0) 47 | this.Role = readConfig("config/csv/hero.csv", 0) 48 | 49 | } 50 | -------------------------------------------------------------------------------- /server/src/server/gameServer/game/equip.go: -------------------------------------------------------------------------------- 1 | //装备相关 2 | package game 3 | 4 | type Equip struct { 5 | equip_id int32 6 | pos int32 7 | } 8 | 9 | func (this *Equip) Init() { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /server/src/server/gameServer/game/hangUp.go: -------------------------------------------------------------------------------- 1 | //挂机相关 2 | package game 3 | 4 | type HangUp struct { 5 | } 6 | 7 | func (this *HangUp) Init() { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /server/src/server/gameServer/game/hangUpCoast.go: -------------------------------------------------------------------------------- 1 | //秘境挂机 2 | package game 3 | 4 | type HangUpCoast struct { 5 | } 6 | 7 | func (this *HangUpCoast) Init() { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /server/src/server/gameServer/game/init.go: -------------------------------------------------------------------------------- 1 | package game 2 | 3 | var Csv *CsvConfig 4 | 5 | func init() { 6 | Csv = new(CsvConfig) 7 | Csv.Init() 8 | } 9 | -------------------------------------------------------------------------------- /server/src/server/gameServer/game/item.go: -------------------------------------------------------------------------------- 1 | //任务 2 | package game 3 | 4 | //"math/rand" 5 | 6 | type ItemTemplate struct { //产生物品的模板 7 | Attack_Low int32 8 | Attack_Low_Delta int32 9 | Attack_High int32 10 | Attack_High_Delta int32 11 | Defence int32 12 | Defence_Delta int32 13 | Life int32 14 | Life_Delta int32 15 | } 16 | 17 | type PetTemplate struct { //产生宠物的模板 18 | Name string //宠物的名字 19 | Attr ItemTemplate //作为物品的基本属性 20 | LuckLow int32 //最低幸运 21 | LuckDelta int32 //幸运变化区间 22 | Rate int32 //掉落率,10000为基 23 | } 24 | 25 | type ItemConfig struct { 26 | CD []int32 //制作物品冷却时间列表(分钟) 27 | Adjs []string //物品形容词 28 | Objs []string //物品名字 29 | Templates []ItemTemplate 30 | } 31 | 32 | type Item struct { 33 | Name string //物品的名字 34 | AttackLow int32 //物品的攻击力 35 | AttackHigh int32 //物品攻击力范围,实际产生的攻击为 AttackLow 到 AttackHigh 之间随机 36 | Defence int32 //物品的防御力 37 | Life int32 //物品的生命力 38 | Quality int32 //物品的品质,决定了物品升级所需要的金钱和时间 39 | Value int32 //物品的价值,创建和升级物品所投入金币的总和 40 | } 41 | 42 | func (this *Item) Create(name string, ic *ItemConfig, template *ItemTemplate) { 43 | 44 | } 45 | 46 | func (this *Item) SendMsg() { 47 | 48 | } 49 | -------------------------------------------------------------------------------- /server/src/server/gameServer/game/models.go: -------------------------------------------------------------------------------- 1 | //数据库模型 2 | package game 3 | 4 | //game中的player是游戏中的角色 5 | type Player_Rank struct { 6 | ID int32 `orm:"pk"` 7 | PlayerId int32 8 | ServerId int32 9 | Gold int32 10 | } 11 | -------------------------------------------------------------------------------- /server/src/server/gameServer/game/player.go: -------------------------------------------------------------------------------- 1 | //角色 2 | package game 3 | 4 | import ( 5 | "net" 6 | "server/share/global" 7 | "strconv" 8 | "time" 9 | 10 | "github.com/game_engine/cache/redis" 11 | ) 12 | 13 | type PlayerInfo struct { //角色的基本信息,正常情况不会改变 14 | ID int32 //角色的唯一ID 15 | Nick string //角色的名字 16 | RoleId int32 //配置表中的id 17 | Level int32 //等级 18 | Exp int32 //经验 19 | Hp int32 //血量 20 | Physical_def []int32 //物理防御(升级 ,强化,精炼) 21 | Magic_def []int32 //法术防御 22 | Physical_damage []int32 //物理伤害 23 | Magic_damage []int32 //法术伤害 24 | Equip []int32 //装备 25 | } 26 | 27 | type Player struct { 28 | Info PlayerInfo //角色基础属性 29 | Day int //当前天数 任务重置 30 | DayFightNumber int32 //战斗次数 31 | Conn *net.Conn //角色的网络连接,不需要保存 32 | } 33 | 34 | func (this *Player) Init(conn *net.Conn) { 35 | this.Conn = conn 36 | } 37 | 38 | func LoadPlayer(id string) *Player { //从数据库读取玩家信息 39 | player := new(Player) 40 | err := redis.Find(id, player) 41 | if err == nil { 42 | if time.Now().Day() != int(player.Day) { 43 | player.DayFightNumber = 0 44 | } 45 | return player 46 | } 47 | return nil 48 | } 49 | 50 | func (this *Player) RegisterRole(id int32, player_id int32, server_id int32, nick string, HeroId int32) int32 { 51 | 52 | //检查是否已经拥有了key 53 | key := "role:" + strconv.Itoa(int(id)) 54 | is_exists, _ := redis.Exists(key) 55 | 56 | //检测heroid是否在配置中 57 | HeroId_str := strconv.Itoa(int(HeroId)) 58 | if Csv.Create_role[HeroId_str] == nil { 59 | return global.REGISTERROLEERROR 60 | } 61 | 62 | if is_exists { 63 | this.Day = 0 64 | this.DayFightNumber = 0 65 | this.Info.ID = id 66 | this.Info.Nick = nick 67 | this.Info.RoleId = HeroId 68 | 69 | //写入mysql 做排序 70 | //user := Player_Rank{ID: id, PlayerId: player_id, ServerId: server_id, Gold: 0} 71 | //O.Insert(user) 72 | 73 | //写内存数据库 74 | this.Save() 75 | return global.REGISTERROLESUCCESS 76 | } 77 | 78 | return global.REGISTERROLEERROR 79 | } 80 | 81 | func (this *Player) GetRoleInfo() { 82 | 83 | } 84 | 85 | func (this *Player) Save() error { 86 | this.Day = time.Now().Day() 87 | err := redis.Modify("role:"+strconv.Itoa(int(this.Info.ID)), this) 88 | return err 89 | } 90 | -------------------------------------------------------------------------------- /server/src/server/gameServer/game/sysConfig.go: -------------------------------------------------------------------------------- 1 | //服务器配置 2 | package game 3 | 4 | import ( 5 | "github.com/game_engine/i18n" 6 | "github.com/game_engine/logs" 7 | "github.com/game_engine/orm" 8 | _ "github.com/go-sql-driver/mysql" 9 | ) 10 | 11 | import ( 12 | "fmt" 13 | "strconv" 14 | ) 15 | 16 | //全局性 17 | var O orm.Ormer 18 | var Log *logs.BeeLogger 19 | 20 | type SysConfig struct { 21 | account_log_max int64 22 | mysql_address string 23 | ServerAddress string 24 | Server2AccountAddress string 25 | ServerNoteAddress string 26 | GameId int32 27 | DistanceTime int 28 | } 29 | 30 | func (this *SysConfig) Init() { 31 | this.setLog() 32 | this.readConfig() 33 | this.dbConfig() 34 | } 35 | 36 | func (this *SysConfig) setLog() { 37 | Log = logs.NewLogger(this.account_log_max) //日志 38 | Log.EnableFuncCallDepth(true) 39 | err := Log.SetLogger("file", `{"filename":"log/game.log"}`) 40 | if err != nil { 41 | fmt.Println(err) 42 | } 43 | } 44 | 45 | func (this *SysConfig) readConfig() { 46 | err := il8n.GetInit("config/game_cfg.ini") 47 | if err == nil { 48 | 49 | int_gameid, _ := strconv.Atoi(il8n.Data["game_id"].(string)) 50 | this.GameId = int32(int_gameid) 51 | this.account_log_max, _ = strconv.ParseInt(il8n.Data["account_log_max"].(string), 10, 64) 52 | this.ServerAddress = il8n.Data["server_address"].(string) 53 | this.Server2AccountAddress = il8n.Data["server_2_accont_address"].(string) 54 | this.ServerNoteAddress = il8n.Data["server_note_address"].(string) 55 | this.DistanceTime, _ = strconv.Atoi(il8n.Data["distance_time"].(string)) 56 | this.mysql_address = il8n.Data["mysql_user"].(string) + ":" + il8n.Data["mysql_pwd"].(string) + "@tcp(" + il8n.Data["mysql_ip"].(string) + ":" + il8n.Data["mysql_port"].(string) + ")/" + il8n.Data["mysql_db"].(string) + "?charset=utf8" 57 | } else { 58 | Log.Error(err.Error()) 59 | } 60 | } 61 | 62 | func (this *SysConfig) dbConfig() { 63 | // set default database 64 | err := orm.RegisterDataBase("default", "mysql", this.mysql_address) 65 | if err != nil { 66 | Log.Error(err.Error()) 67 | } 68 | 69 | // register model 70 | orm.RegisterModel(new(Player_Rank)) 71 | 72 | // create table 73 | orm.RunSyncdb("default", false, true) 74 | O = orm.NewOrm() 75 | } 76 | -------------------------------------------------------------------------------- /server/src/server/gameServer/game/town.go: -------------------------------------------------------------------------------- 1 | //主城 2 | package game 3 | 4 | type Town struct { 5 | } 6 | 7 | func (this *Town) Init() { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /server/src/server/gameServer/game/world.go: -------------------------------------------------------------------------------- 1 | //游戏世界 2 | package game 3 | 4 | func Init() { 5 | 6 | } 7 | 8 | type World struct { 9 | players map[string]*Player //世界内玩家指针 map 10 | } 11 | 12 | func (this *World) Init() { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /server/src/server/gameServer/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "encoding/binary" 6 | 7 | "github.com/game_engine/timer" 8 | ) 9 | 10 | import ( 11 | "fmt" 12 | "net" 13 | ) 14 | 15 | var conn2a net.Conn //连接账号服务器 16 | var end = make(chan int) 17 | 18 | var deal_2a *Deal2A 19 | var deal_4c *Deal4C 20 | 21 | func init() { 22 | 23 | deal_4c = new(Deal4C) 24 | deal_4c.Init() 25 | 26 | deal_2a = new(Deal2A) 27 | deal_2a.Init() 28 | 29 | } 30 | 31 | func CheckError(err error) bool { 32 | if err != nil { 33 | fmt.Println("err:", err.Error()) 34 | return false 35 | } 36 | return true 37 | } 38 | 39 | func SendPackage(conn net.Conn, pid int32, body []byte) { 40 | 41 | len := 8 + len(body) 42 | var len_32 = int32(len) 43 | 44 | len_buf := bytes.NewBuffer([]byte{}) 45 | binary.Write(len_buf, binary.BigEndian, len_32) 46 | 47 | pid_buf := bytes.NewBuffer([]byte{}) 48 | binary.Write(pid_buf, binary.BigEndian, pid) 49 | 50 | msg := append(len_buf.Bytes(), pid_buf.Bytes()...) 51 | msg2 := append(msg, body...) 52 | conn.Write(msg2) 53 | } 54 | 55 | func GetHead(buf []byte) (int32, int32) { 56 | if len(buf) < 8 { 57 | return 0, 0 58 | } 59 | 60 | var head_len int32 = 0 61 | var head_pid int32 = 0 62 | buffer_len := bytes.NewBuffer(buf[0:4]) 63 | buffer_pid := bytes.NewBuffer(buf[4:8]) 64 | binary.Read(buffer_len, binary.BigEndian, &head_len) 65 | binary.Read(buffer_pid, binary.BigEndian, &head_pid) 66 | return head_len, head_pid 67 | } 68 | 69 | func main() { 70 | //连接账号服务器 71 | 72 | var err error 73 | conn2a, err = net.Dial("tcp", sys_config.Server2AccountAddress) 74 | if CheckError(err) { 75 | //定时告诉账号服务器当前人数 76 | deal_2a.send2AccountMenber() 77 | timer.CreateTimer(sys_config.DistanceTime, true, deal_2a.send2AccountMenber) 78 | 79 | //接收account服务器发来的消息 80 | go deal_2a.Handler2A(conn2a) 81 | } 82 | 83 | //监听玩家连接 84 | listener1, err1 := net.Listen("tcp", sys_config.ServerAddress) 85 | if CheckError(err1) { 86 | go deal_4c.Deal4Client(listener1) 87 | } 88 | 89 | <-end 90 | } 91 | -------------------------------------------------------------------------------- /server/src/server/loginServer/account/accountMsg.go: -------------------------------------------------------------------------------- 1 | package account 2 | 3 | import ( 4 | "github.com/game_engine/cache/redis" 5 | "github.com/game_engine/i18n" 6 | _ "github.com/go-sql-driver/mysql" 7 | "server/share/global" 8 | "strings" 9 | "sync" 10 | ) 11 | 12 | type AccountInfo struct { 13 | accountMutex *sync.RWMutex 14 | config *Config 15 | } 16 | 17 | func (this *AccountInfo) Init(config *Config) { 18 | this.accountMutex = new(sync.RWMutex) 19 | this.config = config 20 | } 21 | 22 | func (this *AccountInfo) Register(name string, pwd string, server_id string) (int, int) { 23 | this.accountMutex.Lock() 24 | defer this.accountMutex.Unlock() 25 | 26 | //通过内存数据库 先检查是否username相同 27 | redis_login_base := new(LoginBase) 28 | err := redis.Find("PlayerName:"+name, redis_login_base) 29 | if err != nil { //没有查到数据 30 | //写内存数据库与mysql 31 | this.config.count += 1 32 | user := LoginBase{PlayerId: this.config.count, PlayerName: name, PlayerPwd: pwd, Gold: 0, ServerId: server_id, IsForBid: false} 33 | 34 | //内存数据库 35 | err_redis := redis.Add("PlayerName:"+name, user) 36 | //mysql 37 | _, err_mysql := O.Insert(&user) 38 | 39 | if err_redis == nil && err_mysql == nil { 40 | return global.REGISTERSUCCESS, this.config.count 41 | } else { 42 | redis.Del("PlayerName:" + name) 43 | O.Delete(&user) 44 | } 45 | } 46 | 47 | Log.Trace("name = %s pwd = %s have same SAMENICK", name, pwd) 48 | return global.SAMENICK, 0 49 | } 50 | 51 | func (this *AccountInfo) VerifyLogin(name string, pwd string) (result int, player_id int, game_address string) { 52 | redis_login_base := new(LoginBase) 53 | err := redis.Find("PlayerName:"+name, redis_login_base) 54 | if err == nil { 55 | if strings.EqualFold(redis_login_base.PlayerName, name) && strings.EqualFold(redis_login_base.PlayerPwd, pwd) && !redis_login_base.IsForBid { 56 | if v, ok := il8n.Data[redis_login_base.ServerId]; ok { 57 | return global.LOGINSUCCESS, redis_login_base.PlayerId, v.(string) 58 | } else { 59 | Log.Error("user.ServerId not find config for serverList error") 60 | } 61 | } 62 | } 63 | return global.LOGINERROR, 0, "" 64 | } 65 | -------------------------------------------------------------------------------- /server/src/server/loginServer/account/initAccount.go: -------------------------------------------------------------------------------- 1 | package account 2 | 3 | import ( 4 | "fmt" 5 | "github.com/game_engine/i18n" 6 | "github.com/game_engine/logs" 7 | "github.com/game_engine/orm" 8 | _ "github.com/go-sql-driver/mysql" 9 | "strconv" 10 | "strings" 11 | ) 12 | 13 | //全局性 14 | var O orm.Ormer 15 | var Log *logs.BeeLogger 16 | 17 | type Config struct { 18 | count int //现在最大的playerid 19 | account_log_max int64 20 | Listen4CAddress string 21 | Listen4GameAddress string 22 | mysql_address string 23 | NewServerAddress map[string]string //such as [1]"127.0.0.1:1234" 24 | } 25 | 26 | func (this *Config) Init() { 27 | this.NewServerAddress = make(map[string]string) 28 | this.setLog() 29 | this.readConfig() 30 | this.openNewServerConfig() 31 | this.dbConfig() 32 | this.count = this.getMaxId() 33 | } 34 | 35 | func (this *Config) setLog() { 36 | Log = logs.NewLogger(this.account_log_max) //日志 37 | Log.EnableFuncCallDepth(true) 38 | err := Log.SetLogger("file", `{"filename":"log/account.log"}`) 39 | if err != nil { 40 | fmt.Println(err) 41 | } 42 | } 43 | 44 | func (this *Config) readConfig() { 45 | err := il8n.GetInit("config/account_cfg.ini") 46 | if err == nil { 47 | this.account_log_max, _ = strconv.ParseInt(il8n.Data["account_log_max"].(string), 10, 64) 48 | this.Listen4CAddress = il8n.Data["login_listen_4c_ip"].(string) 49 | this.Listen4GameAddress = il8n.Data["login_listen_4game_ip"].(string) 50 | this.mysql_address = il8n.Data["mysql_user"].(string) + ":" + il8n.Data["mysql_pwd"].(string) + "@tcp(" + il8n.Data["mysql_ip"].(string) + ":" + il8n.Data["mysql_port"].(string) + ")/" + il8n.Data["mysql_db"].(string) + "?charset=utf8" 51 | } else { 52 | Log.Error(err.Error()) 53 | } 54 | } 55 | 56 | func (this *Config) openNewServerConfig() { 57 | for k, v := range il8n.Data { 58 | if strings.Contains(k.(string), "new_") { 59 | key := strings.TrimLeft(k.(string), "new_") 60 | this.NewServerAddress[key] = v.(string) 61 | } 62 | } 63 | if len(this.NewServerAddress) == 0 { 64 | Log.Error("new player can't connect,config can't find new server id") 65 | } 66 | } 67 | 68 | func (this *Config) dbConfig() { 69 | err := orm.RegisterDataBase("default", "mysql", this.mysql_address) 70 | if err != nil { 71 | Log.Error(err.Error()) 72 | } 73 | 74 | orm.RegisterModel(new(LoginBase), new(ForBid)) 75 | orm.RunSyncdb("default", false, true) 76 | O = orm.NewOrm() 77 | } 78 | 79 | func (this *Config) getMaxId() int { 80 | var count int = 0 81 | var maps []orm.Params 82 | num, err := O.Raw("select max(player_id) from login_base").Values(&maps) 83 | if err == nil && num > 0 { 84 | if maps[0]["max(player_id)"] != nil { 85 | buff := maps[0]["max(player_id)"].(string) 86 | count, _ = strconv.Atoi(buff) 87 | } 88 | } 89 | return count 90 | } 91 | -------------------------------------------------------------------------------- /server/src/server/loginServer/account/models.go: -------------------------------------------------------------------------------- 1 | package account 2 | 3 | import () 4 | 5 | type LoginBase struct { 6 | PlayerId int `orm:"pk"` 7 | PlayerName string `orm:"size(64)"` 8 | PlayerPwd string `orm:"size(64)"` 9 | Gold int 10 | ServerId string 11 | IsForBid bool 12 | } 13 | 14 | type ForBid struct { 15 | UserId int `orm:"pk"` 16 | ForBidMsg string `orm:"size(1024)"` 17 | } 18 | -------------------------------------------------------------------------------- /server/src/server/loginServer/deal4c.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "encoding/binary" 6 | "fmt" 7 | "net" 8 | "server/loginServer/account" 9 | "server/share/global" 10 | "server/share/protocol" 11 | 12 | "github.com/golang/protobuf/proto" 13 | ) 14 | 15 | type Deal4C struct { 16 | deal4g *Deal4G 17 | account_info *account.AccountInfo 18 | } 19 | 20 | func (this *Deal4C) Init(account_info *account.AccountInfo, deal4g *Deal4G) { 21 | this.account_info = account_info 22 | this.deal4g = deal4g 23 | } 24 | 25 | func (this *Deal4C) Deal4Client(listener net.Listener) { 26 | for { 27 | conn, err := listener.Accept() 28 | fmt.Println(conn.RemoteAddr(), "connected") 29 | if CheckError(err) { 30 | go this.Handler4C(conn) 31 | } 32 | } 33 | } 34 | 35 | func (this *Deal4C) Handler4C(conn net.Conn) { 36 | defer conn.Close() 37 | const MAXLEN = 1024 38 | buf := make([]byte, MAXLEN) 39 | 40 | for { 41 | n, err := conn.Read(buf) //接收具体消息 42 | if err != nil { 43 | return 44 | } 45 | 46 | if n > MAXLEN && n < 8 { 47 | account.Log.Error("recive error n> MAXLEN") 48 | return 49 | } 50 | 51 | //接收包头 52 | var head_len int32 = 0 53 | var head_pid int32 = 0 54 | buffer_len := bytes.NewBuffer(buf[0:4]) 55 | buffer_pid := bytes.NewBuffer(buf[4:8]) 56 | binary.Read(buffer_len, binary.BigEndian, &head_len) 57 | binary.Read(buffer_pid, binary.BigEndian, &head_pid) 58 | 59 | //接收包体 60 | switch head_pid { 61 | 62 | case 1: 63 | //注册 64 | register := new(protocol.Account_RegisterPlayer) 65 | if err := proto.Unmarshal(buf[8:n], register); err == nil { 66 | game_id, _, _ := this.deal4g.getNewAddress() 67 | fmt.Println(register.GetPlayername(), register.GetPassworld()) 68 | result, player_id := this.account_info.Register(register.GetPlayername(), register.GetPassworld(), game_id) 69 | 70 | result4C := &protocol.Account_RegisterResult{ 71 | Result: proto.Int32(int32(result)), 72 | } 73 | 74 | encObj, _ := proto.Marshal(result4C) 75 | SendPackage(conn, 1, encObj) 76 | 77 | //通知game注册成功 78 | if global.REGISTERSUCCESS == result { 79 | err := this.deal4g.NoteGame(player_id, game_id) 80 | if err != nil { 81 | account.Log.Error("err:", err) 82 | } 83 | account.Log.Info("player_id = %d game_id=%d", player_id, game_id) 84 | } 85 | 86 | } 87 | 88 | case 2: 89 | //登陆 90 | login := new(protocol.Account_LoginInfo) 91 | if err := proto.Unmarshal(buf[8:n], login); err == nil { 92 | result, player_id, server_address := this.account_info.VerifyLogin(login.GetPlayername(), login.GetPassworld()) 93 | //发送登陆并断开连接 94 | result4C := &protocol.Account_LoginResult{ 95 | Result: proto.Int32(int32(result)), 96 | PlayerId: proto.Int32(int32(player_id)), 97 | Gameserver: proto.String(server_address), 98 | } 99 | 100 | encObj, _ := proto.Marshal(result4C) 101 | SendPackage(conn, 2, encObj) 102 | conn.Close() 103 | } else { 104 | fmt.Println(err) 105 | } 106 | 107 | default: 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /server/src/server/loginServer/deal4g.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "encoding/binary" 6 | "errors" 7 | "fmt" 8 | "net" 9 | "server/loginServer/account" 10 | "server/share/protocol" 11 | "sync" 12 | 13 | "github.com/golang/protobuf/proto" 14 | ) 15 | 16 | type Connect4C struct { 17 | Address string 18 | Count int 19 | Conn net.Conn 20 | } 21 | 22 | type Deal4G struct { 23 | gameConnects map[string]Connect4C //key: "127.0.0.1:2422" 24 | config *account.Config 25 | deal4gMutex *sync.RWMutex 26 | } 27 | 28 | func (this *Deal4G) Init(config *account.Config) { 29 | this.gameConnects = make(map[string]Connect4C) 30 | this.deal4gMutex = new(sync.RWMutex) 31 | this.config = config 32 | } 33 | 34 | func (this *Deal4G) getNewAddress() (key string, value string, err error) { 35 | this.deal4gMutex.Lock() 36 | defer this.deal4gMutex.Unlock() 37 | 38 | var address string = "" 39 | var max_count int = 99999 40 | var address_id string = "" 41 | 42 | if len(this.config.NewServerAddress) == 0 { 43 | account.Log.Error("account.NewServerAddress len = 0") 44 | return "", "", errors.New("account.NewServerAddress len = 0") 45 | } 46 | 47 | for key, v := range this.config.NewServerAddress { 48 | if this.gameConnects[v].Count <= max_count { 49 | address_id = key 50 | address = this.gameConnects[v].Address 51 | max_count = this.gameConnects[v].Count 52 | } 53 | } 54 | return address_id, address, nil 55 | } 56 | 57 | func (this *Deal4G) Handler4Game(conn net.Conn) { 58 | //game与账号服务器断开 59 | defer func() { 60 | var key string = "" 61 | for _, v := range this.gameConnects { 62 | if v.Conn == conn { 63 | break 64 | } 65 | } 66 | delete(this.gameConnects, key) 67 | conn.Close() 68 | }() 69 | 70 | const MAXLEN = 1024 71 | buf := make([]byte, MAXLEN) 72 | for { 73 | n, err := conn.Read(buf) //接收具体消息 74 | if err != nil { 75 | return 76 | } 77 | 78 | if n > MAXLEN { 79 | account.Log.Error("recive error n> MAXLEN") 80 | return 81 | } 82 | 83 | var head_len int32 = 0 84 | var head_pid int32 = 0 85 | buffer_len := bytes.NewBuffer(buf[0:4]) 86 | buffer_pid := bytes.NewBuffer(buf[4:8]) 87 | binary.Read(buffer_len, binary.BigEndian, &head_len) 88 | binary.Read(buffer_pid, binary.BigEndian, &head_pid) 89 | 90 | fmt.Println("head_pid", head_pid, "head_len=", head_len) 91 | switch head_pid { 92 | case 101: 93 | get_account := new(protocol.Account_GameResult) 94 | if err := proto.Unmarshal(buf[8:n], get_account); err == nil { 95 | key := get_account.GetGameAddress() 96 | this.gameConnects[key] = Connect4C{get_account.GetGameAddress(), int(get_account.GetCount()), conn} 97 | } 98 | default: 99 | } 100 | 101 | } 102 | } 103 | 104 | func (this *Deal4G) Deal4GameServer(listener net.Listener) { 105 | for { 106 | conn, err := listener.Accept() 107 | fmt.Println(conn.RemoteAddr().String(), " connet") 108 | if CheckError(err) { 109 | go this.Handler4Game(conn) 110 | } 111 | } 112 | } 113 | 114 | func (this *Deal4G) NoteGame(player_id int, game_id string) error { 115 | result4G := &protocol.Account_NoteGame{ 116 | PlayerId: proto.Int32(int32(player_id)), 117 | } 118 | 119 | encObj, _ := proto.Marshal(result4G) 120 | server_address := this.config.NewServerAddress[game_id] 121 | 122 | if _, ok := this.gameConnects[server_address]; ok { 123 | SendPackage(this.gameConnects[server_address].Conn, 102, encObj) 124 | fmt.Println("send to game", encObj) 125 | return nil 126 | } 127 | return errors.New("game connect error") 128 | } 129 | -------------------------------------------------------------------------------- /server/src/server/loginServer/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "encoding/binary" 6 | "fmt" 7 | "net" 8 | "server/loginServer/account" 9 | ) 10 | 11 | var end = make(chan int) 12 | var config *account.Config 13 | var account_info *account.AccountInfo 14 | var deal_4g *Deal4G 15 | var deal_4c *Deal4C 16 | 17 | func init() { 18 | config = new(account.Config) 19 | config.Init() 20 | 21 | account_info = new(account.AccountInfo) 22 | account_info.Init(config) 23 | 24 | deal_4g = new(Deal4G) 25 | deal_4g.Init(config) 26 | 27 | deal_4c = new(Deal4C) 28 | deal_4c.Init(account_info, deal_4g) 29 | 30 | } 31 | 32 | func CheckError(err error) bool { 33 | if err != nil { 34 | fmt.Println("err:", err.Error()) 35 | return false 36 | } 37 | return true 38 | } 39 | 40 | func SendPackage(conn net.Conn, pid int, body []byte) { 41 | var pid_32 int32 = int32(pid) 42 | len := 8 + len(body) 43 | var len_32 = int32(len) 44 | 45 | len_buf := bytes.NewBuffer([]byte{}) 46 | binary.Write(len_buf, binary.BigEndian, len_32) 47 | 48 | pid_buf := bytes.NewBuffer([]byte{}) 49 | binary.Write(pid_buf, binary.BigEndian, pid_32) 50 | 51 | msg := append(len_buf.Bytes(), pid_buf.Bytes()...) 52 | msg2 := append(msg, body...) 53 | conn.Write(msg2) 54 | } 55 | 56 | func main() { 57 | 58 | //Deal4Client 59 | listener, err := net.Listen("tcp", config.Listen4CAddress) 60 | 61 | //Deal4Game 62 | listener2, err2 := net.Listen("tcp", config.Listen4GameAddress) 63 | 64 | if !CheckError(err) || !CheckError(err2) { 65 | return 66 | } 67 | 68 | go deal_4c.Deal4Client(listener) 69 | go deal_4g.Deal4GameServer(listener2) 70 | 71 | <-end 72 | } 73 | -------------------------------------------------------------------------------- /server/src/server/share/global/global.go: -------------------------------------------------------------------------------- 1 | package global 2 | 3 | import () 4 | 5 | //用于全局 6 | 7 | func init() { 8 | 9 | } 10 | 11 | //账号服务器消息 12 | const ( 13 | REGISTERSUCCESS = 0 //注册成功 14 | REGISTERERROR = 1 //注册错误 15 | LOGINERROR = 2 //登陆错误 16 | PASSWDERROR = 3 //密码错误 17 | SAMENICK = 4 //注册名字相同 18 | LOGINSUCCESS = 5 //登陆成功 19 | FORBIDLOGIN = 6 //禁止登陆 20 | ) 21 | 22 | //游戏服务器 23 | const ( 24 | REGISTERROLESUCCESS = 100 //注册角色成功 25 | REGISTERROLEERROR = 101 //注册角色失败 26 | 27 | ) 28 | -------------------------------------------------------------------------------- /server/src/server/share/global/locale_zh-CN.ini: -------------------------------------------------------------------------------- 1 | lang = zh-CN 2 | hi = 你好 3 | bye = 再见 -------------------------------------------------------------------------------- /server/src/testServer/testLoginServer/testLoginServer.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hujunlong/doudizhu/da5ee651b3f66d3db844b4314ebcaf1c0170413a/server/src/testServer/testLoginServer/testLoginServer.exe --------------------------------------------------------------------------------