void PacketHandler::S_SHOOT_HANDLER(std::shared_ptr<OBJECT> ob) { char buffer[BUFSIZE] = { 0, }; unsigned short size = 0, type = 0; InGamePacket::S_Shoot ServerShootPacket; std::shared_ptr<BULLET> Bullet = std::static_pointer_cast<BULLET>(ob); ServerShootPacket.set_uid(Bullet->shooter); ServerShootPacket.set_damage(Bullet->damage); ServerShootPacket.set_bullet_uid(Bullet->ObjectId); ServerShootPacket.set_x(Bullet->x); ServerShootPacket.set_y(Bullet->y); ServerShootPacket.set_vx(Bullet->vx); ServerShootPacket.set_vy(Bullet->vy); InGamePacket::S_Acceleration *temp = ServerShootPacket.add_acceleration_list(); temp->set_ax(Bullet->ax); temp->set_ay(Bullet->ay); type = PKT_S_SHOOT; size = ServerShootPacket.ByteSize(); memcpy(buffer, &size, sizeof(size)); memcpy(buffer + sizeof(size), &type, sizeof(type)); ServerShootPacket.SerializeToArray(buffer + sizeof(unsigned short)* 2, size); BroadCast(buffer, size + sizeof(unsigned short)* 2); return; }
void PacketHandler::S_MOVE_HANDLER(std::shared_ptr<OBJECT> ob) { char buffer[BUFSIZE] = { 0, }; memset(buffer, 0, sizeof(buffer)); unsigned short size = 0, type, current = 0; InGamePacket::S_Move ServerMovePacket; ServerMovePacket.set_uid(ob->ObjectId); ServerMovePacket.set_x(ob->x); ServerMovePacket.set_y(ob->y); ServerMovePacket.set_vx(ob->vx); ServerMovePacket.set_vy(ob->vy); InGamePacket::S_Acceleration *temp = ServerMovePacket.add_acceleration_list(); temp->set_ax(0.0f); temp->set_ay(0.0f); size = ServerMovePacket.ByteSize(); type = PKT_S_MOVE; memcpy(buffer, &size, sizeof(size)); memcpy(buffer + sizeof(size), &type, sizeof(type)); ServerMovePacket.SerializeToArray(buffer + sizeof(unsigned short)* 2, size); BroadCast(buffer, size + sizeof(unsigned short)* 2); return; }
void ActiveParty:: BroadcastInfoMessageToAllMembers(const char *buffer) { int wpos = 0; char SendBuf[24576]; //Holds data that is being prepared for sending wpos += PrepExt_SendInfoMessage(&SendBuf[wpos], buffer, INFOMSG_INFO); BroadCast(SendBuf, wpos); }
void SGBattle::SendCurrentTurn() { SFRoom* pRoom = GetOwner()->GetOwner(); auto& roomMember = pRoom->GetRoomMemberMap(); int currentUserID = m_pSevenGameManager->GetCurrentUserID(); SGUser* pSGUser = m_pSevenGameManager->FindUser(currentUserID); SFProtobufPacket<SevenGamePacket::CurrentTurn> currentTurn(SevenGame::CurrentTurn); if (pSGUser->GetID() <= 0) { currentTurn.GetData().set_playerindex(pSGUser->GetID()); currentTurn.GetData().set_playername("AI"); } else { auto& iter = roomMember.find(pSGUser->GetID()); SFASSERT(iter != roomMember.end()); SFPlayer* pCurrentTurnPlayer = iter->second; currentTurn.GetData().set_playerindex(pCurrentTurnPlayer->GetSerial()); currentTurn.GetData().set_playername(pCurrentTurnPlayer->GetPlayerName()); } m_dwLastPlayTickCount = GetTickCount(); BroadCast(currentTurn); }
void SGBattle::SendWinner() { SFProtobufPacket<SevenGamePacket::Winner> winner(SevenGame::Winner); winner.GetData().set_playerindex(*(m_pSevenGameManager->m_vecWinner.begin())); BroadCast(winner); }
void SGBattle::SendCardSubmit(int serial, SCardInfo& cardInfo) { SFProtobufPacket<SevenGamePacket::CardSubmit> cardSubmit(SevenGame::CardSubmit); cardSubmit.GetData().set_playerindex(serial); cardSubmit.GetData().set_cardnum(cardInfo.iCardNum); cardSubmit.GetData().set_cardtype(cardInfo.iCardType); BroadCast(cardSubmit); }
void SGBattle::SendTurnPass(int serial) { SGUser* pUser = m_pSevenGameManager->FindUser(serial); SFProtobufPacket<SevenGamePacket::TurnPass> turnPass(SevenGame::TurnPass); turnPass.GetData().set_playerindex(serial); turnPass.GetData().set_ticketcount(pUser->GetPassTicketCnt()); BroadCast(turnPass); }
void PacketHandler::C_SHOOT_HANDLER(Packet& p) { char buffer[BUFSIZE] = { 0, }; unsigned short size = 0, type = 0; int index; InGamePacket::C_Shoot ClientBullet; ClientBullet.ParseFromArray(p.Msg, p.getLength()); std::shared_ptr<BULLET> Bullet; std::shared_ptr<USER> tempUser; { index = IocpConstructor::Object_Manager->FIND_USER(p.socket); tempUser = std::static_pointer_cast<USER>(IocpConstructor::Object_Manager->FIND(index)); std::shared_ptr<BULLET> tempBullet(new BULLET(tempUser->x, tempUser->y, ClientBullet.unit_vx()*BULLET_VELOCITY, ClientBullet.unit_vy()*BULLET_VELOCITY, index)); Bullet = tempBullet; IocpConstructor::Object_Manager->REGIST_BULLET(Bullet); } //총 움직임에 대한 'JOB'처리 TimerJob job; job.exectime = GetTickCount() + 30; job.func = std::bind(&BULLET::BULLET_MOVE, Bullet); //만약에 안되면 여기 의심 { LOCKING(&IocpConstructor::queueLock); IocpConstructor::jobs.push_back(job); } Bullet->vx = Bullet->vx + Bullet->ax * 0.03f; Bullet->vy = Bullet->vy + Bullet->ay * 0.03f; Bullet->x += (Bullet->vx*0.03f); Bullet->y += (Bullet->vy*0.03f); //AccountPacket::S_Account_List::Account *tempAccount = tempList.add_account_member(); InGamePacket::S_Shoot ServerShootPacket; ServerShootPacket.set_uid(index); ServerShootPacket.set_damage(Bullet->damage); ServerShootPacket.set_bullet_uid(Bullet->ObjectId); ServerShootPacket.set_x(Bullet->x); ServerShootPacket.set_y(Bullet->y); ServerShootPacket.set_vx(Bullet->vx); ServerShootPacket.set_vy(Bullet->vy); InGamePacket::S_Acceleration *temp = ServerShootPacket.add_acceleration_list(); temp->set_ax(Bullet->ax); temp->set_ay(Bullet->ay); type = PKT_S_SHOOT; size = ServerShootPacket.ByteSize(); memcpy(buffer, &size, sizeof(size)); memcpy(buffer + sizeof(size), &type, sizeof(type)); ServerShootPacket.SerializeToArray(buffer + sizeof(unsigned short)* 2, size); BroadCast(buffer, size + sizeof(unsigned short)* 2); return; }
void SGBattle::SendUserDie(int playerIndex) { SendTableUpdate(); SFProtobufPacket<SevenGamePacket::UserDie> userDie(SevenGame::UserDie); userDie.GetData().set_playerindex(playerIndex); BroadCast(userDie); }
void stQueueRoom::Update() { stBaseRoom::Update(); if(m_stCurMicTempId == 0) { stQueueInfo * p_info = m_stMicQueue.GetFirstMic(); if(p_info) { m_stCurMicTempId = p_info->m_stTempId; memset(m_strCurMicUniqueId, 0, sizeof(m_strCurMicUniqueId)); strncpy(m_strCurMicUniqueId, p_info->uniqueid, sizeof(m_strCurMicUniqueId) - 1); m_CurMicTime = stInfoTick::m_stRTime.GetMSec(); Cmd::cmdNotifyTakeMic send_cmd; send_cmd.set_tempid(m_stCurMicTempId); send_cmd.set_uniqueid(m_strCurMicUniqueId); send_cmd.set_mtime(MIC_TIME); BroadCast(Cmd::enNotifyTakeMic, &send_cmd, send_cmd.ByteSize()); Global::logger->debug("[get_mic] notify cur who get mic change <tempid=%llu,uniqueid=%s>", m_stCurMicTempId, m_strCurMicUniqueId); delete p_info; } } else { if(m_CurMicTime + MIC_TIME * 1000 < stInfoTick::m_stRTime.GetMSec()) { Global::logger->debug("[leave_mic] mic time out will leave <tempid=%llu,uniqueid=%s>", m_stCurMicTempId, m_strCurMicUniqueId); m_stCurMicTempId = 0; memset(m_strCurMicUniqueId, 0, sizeof(m_strCurMicUniqueId)); Cmd::cmdNotifyTakeMic send_cmd; send_cmd.set_tempid(m_stCurMicTempId); send_cmd.set_uniqueid(m_strCurMicUniqueId); send_cmd.set_mtime(MIC_TIME); BroadCast(Cmd::enNotifyTakeMic, &send_cmd, send_cmd.ByteSize()); Global::logger->debug("[get_mic] notify cur not any get mic, stop play <tempid=%llu>", m_stCurMicTempId); } } }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ret = DeviceInit(); BroadCast(); ui->setupUi(this); //addTableItem("test", 0, 0, "tfc"); MainListSet(); }
void SGBattle::SendTableUpdate() { SFProtobufPacket<SevenGamePacket::TableUpdate> tableUpdate(SevenGame::TableUpdate); SGTable* pTable = m_pSevenGameManager->GetTable(); int *paSpadeTable = pTable->GetSpadeTableArray(); int *paHeartTable = pTable->GetHeartTableArray(); int *paCloverTable = pTable->GetCloverTableArray(); int *paDiamondTable = pTable->GetDiamondTableArray(); for(int i=1; i<=MAX_CARD_NUM; i++ ) { if(paSpadeTable[i] != -1) { SevenGamePacket::TableUpdate::AddCard* pCard = tableUpdate.GetData().add_card(); pCard->set_cardnum(paSpadeTable[i]); pCard->set_cardtype(TYPE_SPADE); } } for(int i=1; i<=MAX_CARD_NUM; i++ ) { if(paHeartTable[i] != -1) { SevenGamePacket::TableUpdate::AddCard* pCard = tableUpdate.GetData().add_card(); pCard->set_cardnum(paHeartTable[i]); pCard->set_cardtype(TYPE_HEART); } } for(int i=1; i<=MAX_CARD_NUM; i++ ) { if(paCloverTable[i] != -1) { SevenGamePacket::TableUpdate::AddCard* pCard = tableUpdate.GetData().add_card(); pCard->set_cardnum(paCloverTable[i]); pCard->set_cardtype(TYPE_CLOVER); } } for(int i=1; i<=MAX_CARD_NUM; i++ ) { if(paDiamondTable[i] != -1) { SevenGamePacket::TableUpdate::AddCard* pCard = tableUpdate.GetData().add_card(); pCard->set_cardnum(paDiamondTable[i]); pCard->set_cardtype(TYPE_DIAMOND); } } BroadCast(tableUpdate); }
void ActiveParty :: Disband(char *buffer) { if(mMemberList.size() == 0) return; int wpos = PartyManager::WriteLeftParty(buffer); for(size_t i = 0; i < mMemberList.size(); i++) { if(mMemberList[i].mCreaturePtr != NULL) mMemberList[i].mCreaturePtr->PartyID = 0; } BroadCast(buffer, wpos); mMemberList.clear(); }
//stop 패킷 받았을경우 처리방법, 생각해보자..-> "USER"한테 오는 경우만 신경써주면 된다 void PacketHandler::C_STOP_HANDLER(Packet& p) { char buffer[BUFSIZE] = { 0, }; memset(buffer, 0, sizeof(buffer)); unsigned short size = 0, type = 0, current = 0; int receiveType; InGamePacket::C_Stop StopPacket; StopPacket.ParseFromArray(p.Msg, p.getLength()); InGamePacket::S_Stop ServerStopPacket; std::shared_ptr<OBJECT> tempObject = IocpConstructor::Object_Manager->FIND(StopPacket.uid()); if (tempObject->type == Object_USER) { std::shared_ptr<USER> User = std::static_pointer_cast<USER>(IocpConstructor::Object_Manager->FIND(StopPacket.uid())); User->ChangeState(USER::state::STOP); ServerStopPacket.set_uid(StopPacket.uid()); ServerStopPacket.set_x(StopPacket.x()); ServerStopPacket.set_y(StopPacket.y()); } /*else if (tempObject->type == Object_NPC) { std::shared_ptr<NPC> Npc = std::static_pointer_cast<NPC>(IocpConstructor::Object_Manager->FIND(StopPacket.uid())); Npc->ChangeDirection(); ServerStopPacket.set_uid(StopPacket.uid()); ServerStopPacket.set_x(Npc->x); ServerStopPacket.set_y(Npc->y); }*/ else if (tempObject->type == Object_BULLET) { ServerStopPacket.set_uid(StopPacket.uid()); ServerStopPacket.set_x(StopPacket.x()); ServerStopPacket.set_y(StopPacket.y()); } size = ServerStopPacket.ByteSize(); type = PKT_S_STOP; memcpy(buffer, &size, sizeof(size)); memcpy(buffer + sizeof(size), &type, sizeof(type)); ServerStopPacket.SerializeToArray(buffer + sizeof(unsigned short)* 2, size); BroadCast(buffer, size + sizeof(unsigned short)* 2); return; }
void PacketHandler::S_DISCONNECT_HANDLER(int ObjectID) { char buffer[BUFSIZE] = { 0, }; unsigned short size = 0, type = 0; AccountPacket::S_Account_List::Disconnect disconnect; type = PKT_S_DISCONNECT; disconnect.set_uid(ObjectID); size = disconnect.ByteSize(); memcpy(buffer, &size, sizeof(unsigned short)); memcpy(buffer + sizeof(unsigned short), &type, sizeof(unsigned short)); disconnect.SerializeToArray(buffer + sizeof(unsigned short)* 2, size); BroadCast(buffer, size + sizeof(unsigned short)* 2); return; }
void KSubWorld::Activate() { if (m_SubWorldID == -1) return; m_dwCurrentTime ++; #ifndef _SERVER g_ScenePlace.SetCurrentTime(m_dwCurrentTime); NpcSet.ClearActivateFlagOfAllNpc(); #endif for (int i = 0; i < m_nTotalRegion; i++) { if (m_Region[i].IsActive()) { // g_DebugLog("[Region]%d Activating", i); m_Region[i].Activate(); nActiveRegionCount++; } } #ifdef _SERVER KIndexNode* pNode = (KIndexNode *)m_NoneRegionNpcList.GetHead(); while(pNode) { Npc[pNode->m_nIndex].Activate(); pNode = (KIndexNode *)pNode->GetNext(); } if(m_pWeatherMgr) { int nWeather = m_pWeatherMgr->Activate(); if(m_nWeather != nWeather) { m_nWeather = nWeather; SYNC_WEATHER weatherMsg; weatherMsg.ProtocolType = s2c_changeweather; weatherMsg.WeatherID = (BYTE)m_nWeather; BroadCast((const char*)&weatherMsg, sizeof(SYNC_WEATHER)); } } m_MissionArray.Activate(); #endif }
void stQueueRoom::DelQueueUser(stInfoUser * p_user) { if(m_stCurMicTempId == p_user->GetTempId()) { m_stCurMicTempId = 0; memset(m_strCurMicUniqueId, 0, sizeof(m_strCurMicUniqueId)); m_CurMicTime = 0; Cmd::cmdNotifyTakeMic send_cmd; send_cmd.set_tempid(m_stCurMicTempId); send_cmd.set_uniqueid(m_strCurMicUniqueId); send_cmd.set_mtime(MIC_TIME); BroadCast(Cmd::enNotifyTakeMic, &send_cmd, send_cmd.ByteSize()); } Global::logger->debug("[leave_mic] del mic from queue <roomid=%llu, tempid=%llu>", roomid, p_user->GetTempId()); m_stMicQueue.DelQueueUser(p_user); BroadCastMicQueue(); }
void PacketHandler::S_COLLISION_HANDLER(std::shared_ptr<OBJECT> ob_1, std::shared_ptr<OBJECT> ob_2) { auto instancePtr1 = ob_1, instancePtr2 = ob_2; char buffer[BUFSIZE] = { 0, }; unsigned short size = 0, type = 0; InGamePacket::S_Collision ServerCollisionPacket; //총알 - 맵, 유저 - 맵, 엔피씨 - 맵 if (ob_2 == NULL) { ServerCollisionPacket.set_uid1(ob_1->ObjectId); ServerCollisionPacket.set_x(ob_1->x); ServerCollisionPacket.set_y(ob_1->y); } //총알 - 유저, 총알 - 엔피씨 else if (ob_1->type == Object_BULLET && (ob_2->type == Object_USER || ob_2->type == Object_NPC)) { ServerCollisionPacket.set_uid1(ob_1->ObjectId); ServerCollisionPacket.set_uid2(ob_2->ObjectId); ServerCollisionPacket.set_hp(ob_2->hp); ServerCollisionPacket.set_x(ob_2->x); ServerCollisionPacket.set_y(ob_2->y); } //총알 - 총알 else if (ob_1->type == Object_BULLET && ob_2->type == Object_BULLET) { ServerCollisionPacket.set_uid1(ob_1->ObjectId); ServerCollisionPacket.set_uid2(ob_2->ObjectId); } type = PKT_S_COLLISION; size = ServerCollisionPacket.ByteSize(); memcpy(buffer, &size, sizeof(unsigned short)); memcpy(buffer + sizeof(unsigned short), &type, sizeof(unsigned short)); ServerCollisionPacket.SerializeToArray(buffer + sizeof(unsigned short)* 2, size); BroadCast(buffer, size + sizeof(unsigned short)* 2); return; }
BOOL SGBattle::SendInitCardCount() { SFRoom* pRoom = GetOwner()->GetOwner(); auto& roomMember = pRoom->GetRoomMemberMap(); SFProtobufPacket<SevenGamePacket::InitCardCount> initCardCount(SevenGame::InitCardCount); for (auto& pos : m_pSevenGameManager->m_userlist) { SGUser* pUser = (SGUser*)(pos); SevenGamePacket::InitCardCount::CardCount* pCardCount = initCardCount.GetData().add_info(); pCardCount->set_playerindex(pUser->GetID()); pCardCount->set_cardcount(pUser->GetRemainCard()); } BroadCast(initCardCount); return TRUE; }
void PacketHandler::S_STOP_HANDLER(std::shared_ptr<OBJECT> ob) { char buffer[BUFSIZE] = { 0, }; memset(buffer, 0, sizeof(buffer)); unsigned short size = 0, type = 0; InGamePacket::S_Stop ServerStopPacket; ServerStopPacket.set_uid(ob->ObjectId); ServerStopPacket.set_x(ob->x); ServerStopPacket.set_y(ob->y); type = PKT_S_STOP; size = ServerStopPacket.ByteSize(); memcpy(buffer, &size, sizeof(unsigned short)); memcpy(buffer + sizeof(unsigned short), &type, sizeof(unsigned short)); ServerStopPacket.SerializeToArray(buffer + sizeof(unsigned short)* 2, size); BroadCast(buffer, size + sizeof(unsigned short)* 2); return; }
void PacketHandler::S_RESPAWN_HANDLER(std::shared_ptr<OBJECT> ob) { char buffer[BUFSIZE] = { 0, }; memset(buffer, 0, sizeof(buffer)); unsigned short size = 0, type, current = 0; InGamePacket::S_Respawn ServerRespawnPacket; std::shared_ptr<USER> User = std::static_pointer_cast<USER>(ob); ServerRespawnPacket.set_uid(User->ObjectId); ServerRespawnPacket.set_hp(100); ServerRespawnPacket.set_x(User->x); ServerRespawnPacket.set_y(User->y); size = ServerRespawnPacket.ByteSize(); type = PKT_S_RESPAWN; memcpy(buffer, &size, sizeof(size)); memcpy(buffer + sizeof(size), &type, sizeof(type)); ServerRespawnPacket.SerializeToArray(buffer + sizeof(unsigned short)* 2, size); BroadCast(buffer, size + sizeof(unsigned short)* 2); return; }
void PacketHandler::BroadCastAccountPacket() { char buffer[BUFSIZE] = { 0, }; memset(buffer, 0, sizeof(buffer)); unsigned short size=0, type, current = 0; AccountPacket::S_Account_List tempList; type = PKT_ACCOUNT_LIST; memcpy(buffer + sizeof(size), &type, sizeof(type)); current = (sizeof(unsigned short)* 2); std::map<int, std::shared_ptr<OBJECT>> Instance_map; { LOCKING(&IocpConstructor::ObjectKey); Instance_map = IocpConstructor::Object_Manager->OBJECT_MAP; } for (auto it : Instance_map) { if (it.second == nullptr) continue; if (it.second->type == Object_USER || it.second->type == Object_NPC) { AccountPacket::S_Account_List::Account *tempAccount = tempList.add_account_member(); tempAccount->set_uid(it.second->ObjectId); tempAccount->set_hp(it.second->hp); tempAccount->set_x(it.second->x); tempAccount->set_y(it.second->y); } } size = tempList.ByteSize(); memcpy(buffer, &size, sizeof(size)); tempList.SerializeToArray(buffer + current, size); BroadCast(buffer, size + current); return; }