/// Constructor; define our commands and instantiate variables. /// initData - The data used to instance the game /// Does not return ParlourBBGame::ParlourBBGame(QueueData &initData) { /// We create our commands here. The first parameter is the text command, and the /// second is the game's interpretation. Feel free to have multiple text commands for /// the same game command. "commands" is a QVector provided by the Framework, and /// CommandRef is a simple command lookup class also provided by the Framework. commands.push_back(CommandRef("join", PFBB_CMD_JOIN)); commands.push_back(CommandRef("start", PFBB_CMD_START)); commands.push_back(CommandRef("play", PFBB_CMD_PLAY)); commands.push_back(CommandRef("status", PFBB_CMD_STATUS)); commands.push_back(CommandRef("hand", PFBB_CMD_HAND)); commands.push_back(CommandRef("turn", PFBB_CMD_TURN)); commands.push_back(CommandRef("help", PFBB_CMD_HELP)); commands.push_back(CommandRef("pstop", PFBB_CMD_STOP)); /// "owner" is not entirely necessary, but helps to find out who created the game, /// and allow them exclusive access to certain commands. Provided by the Framework. owner = initData.getNick(); /// "channel" is required for AddToSendQueue to work. Provided by the Framework. channel = initData.getDest(); /// Instantiate our variables. state = PFBB_STATE_INVITE; lastStart = 0; /// Randomize the seed. srand(time(NULL)); /// Post a welcome message to the channel. AddToSendQueue("BARGAIN BIN game is starting! Type \"join\" to play."); AddToSendQueue("\0034WARNING:\003 Game is in \002beta testing phase\002. Strange things or crashes may occur."); }
/// Requests to start the game are handled here. /// inputData - Command data /// Return - Whether we did anything here (T/F) bool ParlourBBGame::CmdStart(QueueData &inputData) { std::ostringstream sout; /// I would like to announce a stream. /// If we're in the invite phase... if (state == PFBB_STATE_INVITE) { /// Make sure that the owner is calling "start". if (inputData.getNick() != owner) return false; /// Make sure we have enough players. if (players.size() < 4) { AddToSendQueue("\0034Not enough players!\003 Need at least four."); return false; } } /// Otherwise, if it's not the Tally phase, return out. This should not happen. else if (state != PFBB_STATE_TALLY) return false; /// If this is the invite phase, we're starting the game. if (state == PFBB_STATE_INVITE) AddToSendQueue("Let's begin!"); /// If this is the tally phase, let the next player start this hand. else { AddToSendQueue("Let's continue!"); if (++lastStart == players.size()) lastStart = 0; players = lastStart; } deck.clear(); /// Empty the deck... ParlourSupport::GenStdDeck(deck); /// ...and get a new one /// Deal five cards to each player, starting "to the left" of the dealer. for (int X = 0; X < 5; X++) { for (size_t Y = 0; Y < players.size(); Y++) { players++; if (X == 0) (*players).ResetHand(); PushCard(); } } /// Set the state to the in-turn state, allowing players to play. state = PFBB_STATE_INTURN; /// Display turn information. CmdCurTurn(); CmdStatus(); CmdHand(); return true; }
/// Requests to join the game are handled here. /// inputData - Command data /// Return - Whether we did anything here (T/F) bool ParlourBBGame::CmdJoin(QueueData &inputData) { std::ostringstream sout; /// Streeeeeeam~ /// Iterate through our playes, and see if they haven't already joined. for (QVector<BBPlayerData>::iterator readList = players.begin(); readList != players.end(); readList++) { if (readList->Name() == inputData.getNick()) { /// We found that this player already joined; don't let them join again. sout << (*readList) << "\0034, you've already joined!"; AddToSendQueue(sout); return false; } } /// This game takes a maximum of ten players. Don't allow any more than that. if (players.size() == 10) { sout << "\00308,01" << inputData.getNick() << "\0034, the game is full!"; AddToSendQueue(sout); return false; } /// Let's create a player and pop them onto the player vector. { BBPlayerData newPlayer(inputData.getNick()); players.push_back(newPlayer); sout << players.back() << " has joined the game!"; AddToSendQueue(sout); } /// If we have four players, let the owner know privately that the game can start. if (players.size() == 4) { AddToSendQueue("Game is ready. You may now \002start\002 the game, or wait for more players (max 10).", MSG_NOTICE, owner); } /// If we have ten players, let the channel know the game is full. if (players.size() == 10) { sout << "\0034The game is now full. \0038,1" << owner << "\003, \002start\002 the game!"; AddToSendQueue(sout); } return true; }
/// Requests for game status are handled here. /// nick - For whom we're getting their status (default to current player) /// Return - Whether we did anything here (T/F) bool ParlourBBGame::CmdStatus(std::string nick) { std::ostringstream sout; /// I'm a little ostream, short and sout... size_t searchList = 0; /// Our search point in the player list /// If no player specified, assume the current player if (nick.empty()) searchList = (size_t)players; else { /// Search the player list for the specified name. for (searchList = 0; searchList < players.size(); searchList++) { /// If we find it, cut out of the loop. if (MATCH_I(nick, players[searchList].Name())) break; } /// Can't find the player. if (searchList == players.size()) return false; } /// "[Player] ([hand score]/[game score]) - [X] card(s) left." sout << players[searchList] << " (\00307" << players[searchList].HandScore() << "\003/\00309" << players[searchList].GameScore() << "\003) - " << players[searchList].CardsLeft() << " card" << (players[searchList].CardsLeft() != 1 ? "s" : "") << " left."; AddToSendQueue(sout); return true; }
/// Requests for player's hand are handled here. /// nick - For whom we're getting their hand (default to current player) /// Return - Whether we did anything here (T/F) bool ParlourBBGame::CmdHand(std::string nick) { std::ostringstream sout; /// This is my input, this is my out. size_t searchList = 0; /// Search position /// If no nick specified, assume current player. if (nick.empty()) searchList = (size_t)players; else { /// Search the player list for the specified name. for (searchList = 0; searchList < players.size(); searchList++) { /// If we find it, cut out of the loop. if (MATCH_I(nick, players[searchList].Name())) break; } /// Can't find the player. if (searchList == players.size()) return false; } /// If the hand is empty, report it as such. if (players[searchList].CardsLeft() == 0) sout << "Your hand is empty."; /// Otherwise, get the hand from the player class. else sout << "Your hand:" << players[searchList].HandString(); /// Send privately to player. AddToSendQueue(sout, MSG_NOTICE, players[searchList].Name()); return true; }
/// Requests for current turn are handled here. /// Return - Whether we did anything here (pretty much invariably true) bool ParlourBBGame::CmdCurTurn() { /// Pretty self-explanatory here. std::ostringstream sout; sout << (*players) << " is up."; AddToSendQueue(sout); return true; }
void CTraderApi::ReqQryInstrument(const string& szInstrumentId) { if (NULL == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_QryInstrumentField); if (NULL == pRequest) return; CThostFtdcQryInstrumentField& body = pRequest->QryInstrumentField; strncpy(body.InstrumentID,szInstrumentId.c_str(),sizeof(TThostFtdcInstrumentIDType)); AddToSendQueue(pRequest); }
void CTraderApi::ReqQryDepthMarketData(const string& szInstrumentId) { if (nullptr == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_QryDepthMarketDataField); if (nullptr == pRequest) return; CSecurityFtdcQryDepthMarketDataField& body = pRequest->QryDepthMarketDataField; strncpy(body.InstrumentID,szInstrumentId.c_str(),sizeof(TSecurityFtdcInstrumentIDType)); AddToSendQueue(pRequest); }
void CTraderApi::ReqQuoteSubscribe() { if (NULL == m_pApi) return; WriteLog("ReqQuoteSubscribe"); SRequest* pRequest = MakeRequestBuf(E_QuoteSubscribeField); if (NULL == pRequest) return; DFITCQuoteSubscribeField * body = (DFITCQuoteSubscribeField*)pRequest->pBuf; strncpy(body->accountID,m_szAccountID.c_str(),sizeof(DFITCAccountIDType)); AddToSendQueue(pRequest); }
void CTraderApi::ReqQryCustomerCapital() { if (NULL == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_CapitalField); if (NULL == pRequest) return; DFITCCapitalField* body = (DFITCCapitalField*)pRequest->pBuf; strncpy(body->accountID, m_szAccountID.c_str(),sizeof(DFITCAccountIDType)); AddToSendQueue(pRequest); }
void CTraderApi::ReqQryTradingAccount() { if (NULL == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_QryTradingAccountField); if (NULL == pRequest) return; CThostFtdcQryTradingAccountField& body = pRequest->QryTradingAccountField; strncpy(body.BrokerID, m_RspUserLogin.BrokerID,sizeof(TThostFtdcBrokerIDType)); strncpy(body.InvestorID, m_RspUserLogin.UserID,sizeof(TThostFtdcInvestorIDType)); AddToSendQueue(pRequest); }
void CTraderApi::ReqQryTradingAccount() { if (nullptr == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_QryTradingAccountField); if (nullptr == pRequest) return; CSecurityFtdcQryTradingAccountField& body = pRequest->QryTradingAccountField; strcpy(body.BrokerID, m_RspUserLogin.BrokerID); strcpy(body.InvestorID, m_RspUserLogin.UserID); AddToSendQueue(pRequest); }
void CTraderApi::ReqQryInstrument(const string& szInstrumentId, const string& szExchange) { if (nullptr == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_QryInstrumentField); if (nullptr == pRequest) return; CThostFtdcQryInstrumentField& body = pRequest->QryInstrumentField; strncpy(body.ContractID, szInstrumentId.c_str(), sizeof(TThostFtdcInstrumentIDType)); //strncpy(body.ProductID, szExchange.c_str(), sizeof(TThostFtdcProductIDType)); AddToSendQueue(pRequest); }
void CTraderApi::ReqQryMatchInfo(DFITCInstrumentTypeType instrumentType) { if (NULL == m_pApi) return; WriteLog("ReqQryMatchInfo"); SRequest* pRequest = MakeRequestBuf(E_MatchField); if (NULL == pRequest) return; DFITCMatchField* body = (DFITCMatchField*)pRequest->pBuf; strncpy(body->accountID,m_szAccountID.c_str(),sizeof(DFITCAccountIDType)); body->instrumentType = instrumentType; AddToSendQueue(pRequest); }
void CTraderApi::ReqQryArbitrageInstrument(const string& szExchangeId) { if (NULL == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_AbiInstrumentField); if (NULL == pRequest) return; DFITCAbiInstrumentField* body = (DFITCAbiInstrumentField*)pRequest->pBuf; strncpy(body->accountID,m_szAccountID.c_str(),sizeof(DFITCAccountIDType)); strncpy(body->exchangeID,szExchangeId.c_str(),sizeof(DFITCExchangeIDType)); AddToSendQueue(pRequest); }
void CTraderApi::ReqQryInstrument(const string& szInstrumentId, const string& szExchange) { if (nullptr == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_QryInstrumentField); if (nullptr == pRequest) return; CSecurityFtdcQryInstrumentField& body = pRequest->QryInstrumentField; strncpy(body.InstrumentID,szInstrumentId.c_str(),sizeof(TSecurityFtdcInstrumentIDType)); strncpy(body.ExchangeID, szExchange.c_str(), sizeof(TSecurityFtdcExchangeIDType)); AddToSendQueue(pRequest); }
void CTraderApi::ReqQryOrder() { if (nullptr == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_QryOrderField); if (nullptr == pRequest) return; CSecurityFtdcQryOrderField& body = pRequest->QryOrderField; strncpy(body.BrokerID, m_RspUserLogin.BrokerID, sizeof(TSecurityFtdcBrokerIDType)); strncpy(body.InvestorID, m_RspUserLogin.UserID, sizeof(TSecurityFtdcInvestorIDType)); AddToSendQueue(pRequest); }
void CTraderApi::ReqQryPositionDetail(const string& szInstrumentId) { if (NULL == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_PositionDetailField); if (NULL == pRequest) return; DFITCPositionDetailField* body = (DFITCPositionDetailField*)pRequest->pBuf; strncpy(body->accountID, m_szAccountID.c_str(),sizeof(DFITCAccountIDType)); strncpy(body->instrumentID,szInstrumentId.c_str(),sizeof(DFITCInstrumentIDType)); //body->instrumentType; AddToSendQueue(pRequest); }
void CTraderApi::ReqQryExchangeInstrument(const string& szExchangeId,DFITCInstrumentTypeType instrumentType) { if (NULL == m_pApi) return; WriteLog("ReqQryExchangeInstrument %s %d",szExchangeId.c_str(),instrumentType); SRequest* pRequest = MakeRequestBuf(E_ExchangeInstrumentField); if (NULL == pRequest) return; DFITCExchangeInstrumentField* body = (DFITCExchangeInstrumentField*)pRequest->pBuf; strncpy(body->accountID,m_szAccountID.c_str(),sizeof(DFITCAccountIDType)); strncpy(body->exchangeID,szExchangeId.c_str(),sizeof(DFITCExchangeIDType)); body->instrumentType = instrumentType; AddToSendQueue(pRequest); }
void CTraderApi::ReqQryTrade() { if (nullptr == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_QryTradeField); if (nullptr == pRequest) return; CUstpFtdcQryTradeField& body = pRequest->QryTradeField; strcpy(body.BrokerID, m_RspUserInvestor.BrokerID); strcpy(body.UserID, m_RspUserInvestor.UserID); strcpy(body.InvestorID, m_RspUserInvestor.InvestorID); AddToSendQueue(pRequest); }
void CTraderApi::ReqQryInvestorPosition(const string& szInstrumentId, const string& szExchange) { if (nullptr == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_QryInvestorPositionField); if (nullptr == pRequest) return; CSecurityFtdcQryInvestorPositionField& body = pRequest->QryInvestorPositionField; strcpy(body.BrokerID, m_RspUserLogin.BrokerID); strcpy(body.InvestorID, m_RspUserLogin.UserID); strncpy(body.InstrumentID,szInstrumentId.c_str(),sizeof(TSecurityFtdcInstrumentIDType)); AddToSendQueue(pRequest); }
void CTraderApi::ReqQryInstrumentCommissionRate(const string& szInstrumentId) { if (NULL == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_QryInstrumentCommissionRateField); if (NULL == pRequest) return; CThostFtdcQryInstrumentCommissionRateField& body = pRequest->QryInstrumentCommissionRateField; strncpy(body.BrokerID, m_RspUserLogin.BrokerID,sizeof(TThostFtdcBrokerIDType)); strncpy(body.InvestorID, m_RspUserLogin.UserID,sizeof(TThostFtdcInvestorIDType)); strncpy(body.InstrumentID,szInstrumentId.c_str(),sizeof(TThostFtdcInstrumentIDType)); AddToSendQueue(pRequest); }
void CTraderApi::ReqQryUserInvestor() { if (nullptr == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_QryUserInvestorField); if (pRequest) { XRespone(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Doing, 0, nullptr, 0, nullptr, 0, nullptr, 0); CUstpFtdcQryUserInvestorField& body = pRequest->QryUserInvestorField; strncpy(body.BrokerID, m_ServerInfo.BrokerID, sizeof(TUstpFtdcBrokerIDType)); strncpy(body.UserID, m_UserInfo.UserID, sizeof(TUstpFtdcInvestorIDType)); AddToSendQueue(pRequest); } }
void CTraderApi::ReqUserLogin() { if (nullptr == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_ReqUserLoginField); if (pRequest) { XRespone(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Logining, 0, nullptr, 0, nullptr, 0, nullptr, 0); CThostFtdcReqUserLoginField& body = pRequest->ReqUserLoginField; strncpy(body.accountID, m_UserInfo.UserID, sizeof(TThostFtdcTraderIDType)); strncpy(body.password, m_UserInfo.Password, sizeof(TThostFtdcPasswordType)); body.loginType = BANKACC_TYPE; AddToSendQueue(pRequest); } }
void CTraderApi::ReqQryInvestorFee(const string& szInstrumentId) { if (nullptr == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_QryInvestorFeeField); if (nullptr == pRequest) return; CUstpFtdcQryInvestorFeeField& body = pRequest->QryInvestorFeeField; strcpy(body.BrokerID, m_RspUserInvestor.BrokerID); strcpy(body.UserID, m_RspUserInvestor.UserID); strcpy(body.InvestorID, m_RspUserInvestor.InvestorID); strncpy(body.InstrumentID,szInstrumentId.c_str(),sizeof(TUstpFtdcInstrumentIDType)); AddToSendQueue(pRequest); }
void CTraderApi::ReqUserLogin() { if (nullptr == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_ReqUserLoginField); if (pRequest) { XRespone(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Logining, 0, nullptr, 0, nullptr, 0, nullptr, 0); CUstpFtdcReqUserLoginField& body = pRequest->ReqUserLoginField; strncpy(body.UserID, m_UserInfo.UserID, sizeof(TUstpFtdcInvestorIDType)); strncpy(body.BrokerID, m_ServerInfo.BrokerID, sizeof(TUstpFtdcBrokerIDType)); strncpy(body.Password, m_UserInfo.Password, sizeof(TUstpFtdcPasswordType)); strncpy(body.UserProductInfo, m_ServerInfo.UserProductInfo, sizeof(TUstpFtdcProductInfoType)); AddToSendQueue(pRequest); } }
void CTraderApi::ReqSettlementInfoConfirm() { if (NULL == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_SettlementInfoConfirmField); if (pRequest) { m_status = E_confirming; if(m_msgQueue) m_msgQueue->Input_OnConnect(this,NULL,m_status); CThostFtdcSettlementInfoConfirmField& body = pRequest->SettlementInfoConfirmField; strncpy(body.BrokerID, m_szBrokerId.c_str(),sizeof(TThostFtdcBrokerIDType)); strncpy(body.InvestorID, m_szInvestorId.c_str(),sizeof(TThostFtdcInvestorIDType)); AddToSendQueue(pRequest); } }
void CTraderApi::ReqUserLogin() { if (NULL == m_pApi) return; WriteLog("ReqUserLogin"); SRequest* pRequest = MakeRequestBuf(E_UserLoginField); if (pRequest) { m_status = E_logining; if(m_msgQueue) m_msgQueue->Input_OnConnect(this,NULL,m_status); DFITCUserLoginField* body = (DFITCUserLoginField*)pRequest->pBuf; strncpy(body->accountID, m_szAccountID.c_str(),sizeof(DFITCAccountIDType)); strncpy(body->passwd, m_szPassword.c_str(),sizeof(DFITCPasswdType)); body->companyID = m_sCompanyID; AddToSendQueue(pRequest); } }
void CTraderApi::ReqAuthenticate() { if (NULL == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_ReqAuthenticateField); if (pRequest) { m_status = E_authing; if(m_msgQueue) m_msgQueue->Input_OnConnect(this,NULL,m_status); CThostFtdcReqAuthenticateField& body = pRequest->ReqAuthenticateField; strncpy(body.BrokerID, m_szBrokerId.c_str(),sizeof(TThostFtdcBrokerIDType)); strncpy(body.UserID, m_szInvestorId.c_str(),sizeof(TThostFtdcInvestorIDType)); strncpy(body.UserProductInfo,m_szUserProductInfo.c_str(),sizeof(TThostFtdcProductInfoType)); strncpy(body.AuthCode,m_szAuthCode.c_str(),sizeof(TThostFtdcAuthCodeType)); AddToSendQueue(pRequest); } }
void CTraderApi::ReqUserLogin() { if (NULL == m_pApi) return; SRequest* pRequest = MakeRequestBuf(E_ReqUserLoginField); if (pRequest) { m_status = E_logining; if(m_msgQueue) m_msgQueue->Input_OnConnect(this,NULL,m_status); CThostFtdcReqUserLoginField& body = pRequest->ReqUserLoginField; strncpy(body.BrokerID, m_szBrokerId.c_str(),sizeof(TThostFtdcBrokerIDType)); strncpy(body.UserID, m_szInvestorId.c_str(),sizeof(TThostFtdcInvestorIDType)); strncpy(body.Password, m_szPassword.c_str(),sizeof(TThostFtdcPasswordType)); strncpy(body.UserProductInfo,m_szUserProductInfo.c_str(),sizeof(TThostFtdcProductInfoType)); AddToSendQueue(pRequest); } }