int main(void) { int h = 0; int f = 1; int clientfd, maxfd, nready, i, result; socklen_t len; struct sockaddr_in q; fd_set allset, rset; struct queue_list *clientlist = q_init(); //client fds struct queue_list *battlelist = q_init(); //battles struct queue_list *playerlist = q_init(); //players w/ stats, name etc. int listenfd = bindandlisten(); maxfd = listenfd; FD_ZERO(&allset); FD_SET(listenfd, &allset); while (1) { printf("server on %d iteration\n", h); h++; if (f == 1) { printf("server initialized! \n"); f++; } rset = allset; struct node *bb = battlelist->front; while (bb) { if (bb->content->status == 0) { battle_end(bb->content, playerlist, 0); } bb = bb->next; } printf("attempting to create matches: "); if (matchmaking(playerlist, battlelist) == 1)//find match for two clients each iteration { printf("Battle created with pid %d !\n", bid); bid = bid + 1; } nready = select(maxfd + 1, &rset, NULL, NULL, NULL); //check if there is any client active if (nready == 0) // if no client is active { continue; //go back to the beginning. } else if (nready == -1) //error { perror("select"); continue; } if (FD_ISSET(listenfd, &rset)) //check if listenfd active that connected by any client { printf("a new client is connecting\n"); len = sizeof(q); if ((clientfd = accept(listenfd, (struct sockaddr *)&q, &len)) < 0) //accept the client, *i think* it will reset listenfd to inactive { perror("accept"); exit(1); } FD_SET(clientfd, &allset); //add the client fd in to the set of fd write(clientfd, "What is your name?\r\n", 20); if (clientfd > maxfd) { maxfd = clientfd; //update max # of fd if needed } printf("connection from %s\n", inet_ntoa(q.sin_addr)); addclient(clientfd, q.sin_addr, clientlist); } struct node *p; for(i = 0; i <= maxfd; i++) //iterate through fd set and { if (FD_ISSET(i, &rset)) //check each connected client fd in the set of fd, if anyone becomes active. { for (p = clientlist->front; p != NULL; p = p->next) //TODO: change this for new data structure { if (p->content->fd == i) { result = handle(clientlist, playerlist, p->content); if (result == -1 || result == 5) { if (result == 5) { bid = battle_end(p->content->player, playerlist, 1); printf("battle %d drops due to client disconnected\n", bid); } int tmp_fd = p->fd; removeclient(p->content, clientlist); FD_CLR(tmp_fd, &allset); close(tmp_fd); } break; } } } } } }
bool CHARACTER::AddAffect(DWORD dwType, BYTE bApplyOn, long lApplyValue, DWORD dwFlag, long lDuration, long lSPCost, bool bOverride, bool IsCube ) { // CHAT_BLOCK if (dwType == AFFECT_BLOCK_CHAT && lDuration > 1) { ChatPacket(CHAT_TYPE_INFO, LC_TEXT("운영자 제제로 채팅이 금지 되었습니다.")); } // END_OF_CHAT_BLOCK if (lDuration == 0) { sys_err("Character::AddAffect lDuration == 0 type %d", lDuration, dwType); lDuration = 1; } CAffect * pkAff = NULL; if (IsCube) pkAff = FindAffect(dwType,bApplyOn); else pkAff = FindAffect(dwType); if (dwFlag == AFF_STUN) { if (m_posDest.x != GetX() || m_posDest.y != GetY()) { m_posDest.x = m_posStart.x = GetX(); m_posDest.y = m_posStart.y = GetY(); battle_end(this); SyncPacket(); } } // 이미 있는 효과를 덮어 쓰는 처리 if (pkAff && bOverride) { ComputeAffect(pkAff, false); // 일단 효과를 삭제하고 if (GetDesc()) SendAffectRemovePacket(GetDesc(), GetPlayerID(), pkAff->dwType, pkAff->bApplyOn); } else { // // 새 에펙를 추가 // // NOTE: 따라서 같은 type 으로도 여러 에펙트를 붙을 수 있다. // pkAff = CAffect::Acquire(); m_list_pkAffect.push_back(pkAff); } sys_log(1, "AddAffect %s type %d apply %d %d flag %u duration %d", GetName(), dwType, bApplyOn, lApplyValue, dwFlag, lDuration); sys_log(0, "AddAffect %s type %d apply %d %d flag %u duration %d", GetName(), dwType, bApplyOn, lApplyValue, dwFlag, lDuration); pkAff->dwType = dwType; pkAff->bApplyOn = bApplyOn; pkAff->lApplyValue = lApplyValue; pkAff->dwFlag = dwFlag; pkAff->lDuration = lDuration; pkAff->lSPCost = lSPCost; WORD wMovSpd = GetPoint(POINT_MOV_SPEED); WORD wAttSpd = GetPoint(POINT_ATT_SPEED); ComputeAffect(pkAff, true); if (pkAff->dwFlag || wMovSpd != GetPoint(POINT_MOV_SPEED) || wAttSpd != GetPoint(POINT_ATT_SPEED)) UpdatePacket(); StartAffectEvent(); if (IsPC()) { SendAffectAddPacket(GetDesc(), pkAff); if (IS_NO_SAVE_AFFECT(pkAff->dwType)) return true; TPacketGDAddAffect p; p.dwPID = GetPlayerID(); p.elem.dwType = pkAff->dwType; p.elem.bApplyOn = pkAff->bApplyOn; p.elem.lApplyValue = pkAff->lApplyValue; p.elem.dwFlag = pkAff->dwFlag; p.elem.lDuration = pkAff->lDuration; p.elem.lSPCost = pkAff->lSPCost; db_clientdesc->DBPacket(HEADER_GD_ADD_AFFECT, 0, &p, sizeof(p)); } return true; }