static void updateGPshipshapes(void) { #if 0 { struct gp_shipshape_spacket pkt; pkt.type = SP_GPARAM; pkt.subtype = 3; pkt.shipno = ATT; pkt.race = -1; pkt.nviews = 1; pkt.width = borgcube_width; pkt.height = borgcube_height; sendClientPacket((struct player_spacket *) & pkt); } { struct gp_shipbitmap_spacket pkt; pkt.type = SP_GPARAM; pkt.subtype = 4; pkt.shipno = ATT; pkt.race = -1; pkt.thisview = 0; memcpy(pkt.bitmapdata, borgcube_bits, sizeof(borgcube_bits)); sendClientPacket((struct player_spacket *) & pkt); } #endif }
void updateGameparams(void) { struct gp_sizes_spacket pkt; memset((char *) &pkt, 0, sizeof(pkt)); pkt.type = SP_GPARAM; pkt.subtype = 0; pkt.nplayers = MAXPLAYER; pkt.nteams = 4; pkt.nshiptypes = NUM_TYPES; pkt.nranks = NUMRANKS; pkt.nroyal = NUMROYALRANKS; pkt.nphasers = 1; pkt.ntorps = MAXTORP; pkt.nplasmas = MAXPLASMA; pkt.nthingies = NPTHINGIES; pkt.gthingies = NGTHINGIES; pkt.gwidth = GWIDTH; pkt.flags = 0; pkt.nplanets = configvals->numplanets; sendClientPacket((struct player_spacket *) & pkt); updateGPteams(); if (me == 0 || !(me->p_stats.st_flags & ST_NOBITMAPS)) { updateGPteamlogos(); updateGPshipshapes(); updateGPplanetbitmaps(); } updateGPrank(); updateGProyal(); }
static void send_one_teamlogo(int teamidx, unsigned char *data, int width, int height) { struct gp_teamlogo_spacket pkt; int pwidth; if (width > 99 || height > 99) { printf("logo too big: %dx%d\n", width, height); return; } pkt.type = SP_GPARAM; pkt.subtype = 2; pkt.logowidth = width; pkt.logoheight = height; pkt.teamindex = teamidx; pwidth = (width - 1) / 8 + 1; pkt.thisheight = sizeof(pkt.data) / pwidth; for (pkt.y = 0; pkt.y < height; pkt.y += pkt.thisheight) { if (pkt.y + pkt.thisheight > height) pkt.thisheight = height - pkt.y; memcpy(pkt.data, data + pkt.y * pwidth, pkt.thisheight * pwidth); sendClientPacket((struct player_spacket *) & pkt); } }
void sendFeature(char *name, int feature_type, int value, int arg1, int arg2) { struct feature_cpacket packet; strncpy(packet.name, name, sizeof(packet.name)); packet.type = SP_FEATURE; packet.name[sizeof(packet.name) - 1] = 0; packet.feature_type = feature_type; packet.value = htonl(value); packet.arg1 = arg1; packet.arg2 = arg2; sendClientPacket((struct player_spacket *) & packet); }
static void updateGProyal(void) { int i; struct gp_royal_spacket pkt; pkt.type = SP_GPARAM; pkt.subtype = 6; for (i = 0; i < NUMROYALRANKS; i++) { pkt.rankn = i; strcpy((char *) pkt.name, royal[i].name); sendClientPacket((struct player_spacket *) & pkt); } }
void Client::updateImp(uint32_t tick) { ENetEvent event; while(enet_host_service(mHost, &event, 0)) { switch(event.type) { case ENET_EVENT_TYPE_CONNECT: { break; } case ENET_EVENT_TYPE_RECEIVE: { readServerPacket(event, tick); break; } case ENET_EVENT_TYPE_DISCONNECT: { std::cout << "DISCONNECT" << std::endl; break; } case ENET_EVENT_TYPE_NONE: { break; } default: { std::cout << "UNHANDLED" << std::endl; break; } } } // don't send client updates until we're fully connected if(mServerPeer != nullptr && FAWorld::World::get()->getCurrentLevel() != nullptr) sendClientPacket(); enet_host_flush(mHost); }
void NetManager::update() { mTick++; ENetEvent event; while(enet_host_service(mHost, &event, 0)) { switch(event.type) { case ENET_EVENT_TYPE_CONNECT: { if(mIsServer) { spawnPlayer(event.peer->connectID); mClients.push_back(event.peer); } break; } case ENET_EVENT_TYPE_RECEIVE: { if(mIsServer) readClientPacket(event); else readServerPacket(event); break; } default: { break; } } } if(mIsServer && mClients.size() > 0) sendServerPacket(); else if(mServerPeer != NULL) sendClientPacket(); enet_host_flush(mHost); }
static void updateGPteams(void) { struct gp_team_spacket pkt; int i; for (i = 0; i < NUMTEAM; i++) { pkt.type = SP_GPARAM; pkt.subtype = 1; pkt.index = i; pkt.letter = teams[idx_to_mask(i)].letter; strncpy((char *) pkt.shortname, teams[idx_to_mask(i)].shortname, sizeof(pkt.shortname)); strncpy((char *) pkt.teamname, teams[idx_to_mask(i)].name, sizeof(pkt.teamname)); sendClientPacket((struct player_spacket *) & pkt); } }
static void updateGPrank(void) { int i; struct gp_rank_spacket pkt; pkt.type = SP_GPARAM; pkt.subtype = 5; for (i = 0; i < NUMRANKS; i++) { pkt.rankn = i; pkt.genocides = htonl(ranks[i].genocides); #define COMPUTE_STATS(a, b) (unsigned long)((long double)(a) * (long double)(b)) pkt.milliDI = htonl(COMPUTE_STATS( 1000, ranks[i].di)); pkt.millibattle = htonl(COMPUTE_STATS( 1000, ranks[i].battle)); pkt.millistrat = htonl(COMPUTE_STATS(1000, ranks[i].strategy)); pkt.millispec = htonl(COMPUTE_STATS(1000, ranks[i].specship)); #undef COMPUTE_STATS strcpy((char *) pkt.name, (char *) ranks[i].name); sendClientPacket((struct player_spacket *) & pkt); } }
DriverStation::DriverStation() { m_init = false; /* Initialize private members */ m_client = new DS_Client; m_netConsole = new DS_NetConsole; m_elapsedTime = new DS_ElapsedTime; m_manager = new DS_ProtocolManager; m_protocol = Q_NULLPTR; /* Update internal values and notify object on robot status events */ connect (m_manager, SIGNAL (codeChanged (bool)), this, SLOT (updateRobotStatus (bool))); connect (m_manager, SIGNAL (communicationsChanged (DS_CommStatus)), this, SLOT (updateRobotStatus (DS_CommStatus))); connect (m_manager, SIGNAL (controlModeChanged (DS_ControlMode)), this, SLOT (resetElapsedTimer (DS_ControlMode))); connect (m_manager, SIGNAL (codeChanged (bool)), this, SIGNAL (codeChanged (bool))); connect (m_manager, SIGNAL (communicationsChanged (DS_CommStatus)), this, SIGNAL (communicationsChanged (DS_CommStatus))); connect (m_manager, SIGNAL (controlModeChanged (DS_ControlMode)), this, SIGNAL (controlModeChanged (DS_ControlMode))); connect (m_manager, SIGNAL (diskUsageChanged (int)), this, SIGNAL (diskUsageChanged (int))); connect (m_manager, SIGNAL (ramUsageChanged (int)), this, SIGNAL (ramUsageChanged (int))); connect (m_manager, SIGNAL (cpuUsageChanged (int)), this, SIGNAL (cpuUsageChanged (int))); connect (m_manager, SIGNAL (voltageChanged (QString)), this, SIGNAL (voltageChanged (QString))); connect (m_manager, SIGNAL (voltageBrownoutChanged (bool)), this, SIGNAL (voltageBrownoutChanged (bool))); connect (m_manager, SIGNAL (CANInfoReceived (DS_CAN)), this, SIGNAL (CANInfoReceived (DS_CAN))); connect (m_manager, SIGNAL (emergencyStopped (void)), this, SIGNAL (emergencyStopped (void))); connect (m_manager, SIGNAL (fmsChanged (bool)), this, SIGNAL (fmsChanged (bool))); /* Stop timer when the communications status changes */ connect (m_manager, SIGNAL (communicationsChanged (DS_CommStatus)), m_elapsedTime, SLOT (stopTimer())); /* Robot information has changed */ connect (m_manager, SIGNAL (libVersionChanged (QString)), this, SIGNAL (libVersionChanged (QString))); connect (m_manager, SIGNAL (rioVersionChanged (QString)), this, SIGNAL (rioVersionChanged (QString))); connect (m_manager, SIGNAL (pcmVersionChanged (QString)), this, SIGNAL (pcmVersionChanged (QString))); connect (m_manager, SIGNAL (pdpVersionChanged (QString)), this, SIGNAL (pdpVersionChanged (QString))); /* Sync robot address and calculated IPs automatically */ connect (m_manager, SIGNAL (robotAddressChanged (QString)), m_client, SLOT (setRobotAddress (QString))); /* Update the elapsed time text automatically */ connect (m_elapsedTime, SIGNAL (elapsedTimeChanged (QString)), this, SIGNAL (elapsedTimeChanged (QString))); /* New NetConsole message received */ connect (m_netConsole, SIGNAL (newMessage (QString)), this, SIGNAL (newMessage (QString))); /* Send and read robot packets */ connect (m_client, SIGNAL (dataReceived (QByteArray)), this, SLOT (readRobotPacket (QByteArray))); connect (DS_Timers::getInstance(), SIGNAL (timeout20()), this, SLOT (sendClientPacket())); }
void NetManager::update() { mTick++; ENetEvent event; // TODO: remove this block when we handle level switching properly auto player = FAWorld::World::get()->getCurrentPlayer(); if(player->getLevel()) mLevelIndexTmp = player->getLevel()->getLevelIndex(); else mLevelIndexTmp = -1; while(enet_host_service(mHost, &event, 0)) { switch(event.type) { case ENET_EVENT_TYPE_CONNECT: { if(mIsServer) { auto player = spawnPlayer(-1); // send the client its player id auto packet = enet_packet_create(NULL, sizeof(size_t), ENET_PACKET_FLAG_RELIABLE); size_t position = 0; writeToPacket(packet, position, player->getId()); enet_peer_send(event.peer, RELIABLE_CHANNEL_ID, packet); sendLevel(0, event.peer); sendLevel(1, event.peer); mClients.push_back(event.peer); mServerPlayerList[event.peer->connectID] = player; } break; } case ENET_EVENT_TYPE_RECEIVE: { if(mIsServer) readClientPacket(event); else readServerPacket(event); break; } default: { break; } } } if(mIsServer && mClients.size() > 0) sendServerPacket(); else if(mServerPeer != NULL) sendClientPacket(); enet_host_flush(mHost); }
void intrupt(void) { if (testtime == -1) { struct reserved_spacket sp; /* Give a reasonable period of time to respond to query (and test code if they need to) */ #define RSAREPLYTIMER 30 #ifdef RSA RSA_Client = 0; #endif testtime = RSAREPLYTIMER * 10; makeReservedPacket(&sp); memcpy(testdata, sp.data, RESERVED_SIZE); sendClientPacket(&sp); } else if (testtime != 0) { testtime--; if (testtime==0) { if (report_ident) pmessage2(0, MALL | MJOIN, "GOD->ALL", me->p_no, "%s using %s", me->p_mapchars, me->p_ident); #if defined(RSA) && defined(SHOW_RSA) && defined(SHOW_RSA_FAILURE) if (!hidden && !whitelisted && !bypassed) pmessage2(0, MALL | MJOIN, "GOD->ALL", me->p_no, "%s %.16s is not using a trusted client", ranks[me->p_stats.st_rank].name, me->p_name); #endif if (bypassed) { /* Deal with .bypass entries */ ERROR(3,(".bypass person : %s - logged on\n",me->p_login)); me->p_stats.st_flags |= ST_CYBORG; /* mark for reference */ new_warning(UNDEF,"You are in the .bypass file, be good"); } else { /* User failed to respond to verification query. Bye! */ if (!binconfirm) me->p_stats.st_flags |= ST_CYBORG; /* mark for reference 7/27/91 TC */ else { me->p_explode = 10; me->p_whydead = KQUIT; me->p_status = PEXPLODE; ERROR(3,("User binary failed to verify\n")); #ifdef RSA #ifdef SHOW_RSA pmessage2(0, MALL | MJOIN, "GOD->ALL", me->p_no, "%s %.16s failed to verify", ranks[me->p_stats.st_rank].name, me->p_name); #endif if (RSA_Client==1) new_warning(UNDEF,"No customized binaries. Please use a blessed one."); else if (RSA_Client==2) new_warning(UNDEF,"Wrong Client Version Number!"); else new_warning(UNDEF,"You need a spiffy new RSA client for this server!"); #else new_warning(UNDEF,"No customized binaries. Please use a blessed one."); #endif } } } } if (me->p_status == PFREE) { ERROR(1,("intrupt: exitGame() on PFREE (pid %i)\n",getpid())); exitGame(0); } if (!Observer || me->p_status == PEXPLODE) { if (me->p_status == PEXPLODE || me->p_status == PDEAD) { FD_ZERO(&inputMask); } if (((me->p_status == PDEAD) || (me->p_status == POUTFIT)) && (me->p_ntorp <= 0) && (me->p_nplasmatorp <= 0)) { death(); return; } } if (clue) { if (RECHECK_CLUE && (clueFuse > CLUEINTERVAL)) { clueVerified = 0; clueFuse = 0; clueCount = 0; } if (!clueVerified && (inl_mode || (queues[QU_PICKUP].count != 0))) { clueFuse++; clue_check(); } } auto_features(); updateClient(); }
static void updateGPplanetbitmaps(void) { struct gp_teamplanet_spacket pkt; char buf[40]; unsigned char *data; int width, height; int i; for (i = 0; i < NUMTEAM; i++) { pkt.type = SP_GPARAM; pkt.subtype = 7; pkt.teamn = i; sprintf(buf, "artwork/%d/tplanet", i); if (status2->league == 1) { if (i == 0) sprintf(buf, "artwork/%s/tplanet", status2->home.name); else if (i == 1) sprintf(buf, "artwork/%s/tplanet", status2->away.name); } else if (status2->league) { if (i == status2->home.index) sprintf(buf, "artwork/%s/tplanet", status2->home.name); else if (i == status2->away.index) sprintf(buf, "artwork/%s/tplanet", status2->away.name); } { FILE *fp; fp = fopen(build_path(buf), "r"); if (!fp) continue; /* no image to transmit */ ParseXbmFile(fp, &width, &height, &data); fclose(fp); } if (!data) { continue; } memcpy(pkt.tactical, data, 120); memcpy(pkt.tacticalM, data, 120); free(data); sprintf(buf, "artwork/%d/gplanet", i); if (status2->league == 1) { if (i == 0) sprintf(buf, "artwork/%s/gplanet", status2->home.name); else if (i == 1) sprintf(buf, "artwork/%s/gplanet", status2->away.name); } else if (status2->league) { if (i == status2->home.index) sprintf(buf, "artwork/%s/gplanet", status2->home.name); else if (i == status2->away.index) sprintf(buf, "artwork/%s/gplanet", status2->away.name); } { FILE *fp; fp = fopen(build_path(buf), "r"); if (!fp) continue; /* no image to transmit */ ParseXbmFile(fp, &width, &height, &data); fclose(fp); } if (!data) { continue; } memcpy(pkt.galactic, data, 32); memcpy(pkt.galacticM, data, 32); free(data); sendClientPacket((struct player_spacket *) & pkt); } }