void CloudAtlasControlWindow::dragEventCallback(double x, double y) { if (canMove()) { addOrigin(x, y); update(); } }
/* ============ DropToFloor plants the object on the floor ============ */ void Item::DropToFloor( Event * ) { str fullname; Vector save; PlaceItem(); addOrigin( Vector(0, 0, 1) ); save = origin; if ( gravity > 0.0f ) { if ( !droptofloor( 8192.0f ) ) { gi.WDPrintf( "%s (%d) stuck in world at '%5.1f %5.1f %5.1f'\n", getClassID(), entnum, origin.x, origin.y, origin.z ); setOrigin( save ); setMoveType( MOVETYPE_NONE ); } else { setMoveType( MOVETYPE_NONE ); } } // // if the our global variable doesn't exist, lets zero it out // fullname = str( "playeritem_" ) + getName(); if ( !gameVars.VariableExists( fullname.c_str() ) ) { gameVars.SetVariable( fullname.c_str(), 0 ); } if ( !levelVars.VariableExists( fullname.c_str() ) ) { levelVars.SetVariable( fullname.c_str(), 0 ); } if ( multiplayerManager.inMultiplayer() && gi.Anim_NumForName( edict->s.modelindex, "idle_onground" ) >= 0 ) { animate->RandomAnimate( "idle_onground" ); edict->s.eType = ET_MODELANIM; } }
// send request and get response int ServerConnection::sendRequest(AAAMessage* req, unsigned int& exe) { if (addOrigin(req)) { return AAA_ERROR_MESSAGE; } conn.setIDs(req); if(AAABuildMsgBuffer(req) != AAA_ERR_SUCCESS) { ERROR( " sendRequest(): message buffer not created\n"); return AAA_ERROR_MESSAGE; } int ret = tcp_send(conn.dia_conn, req->buf.s, req->buf.len); if (ret) { ERROR( " sendRequest(): could not send message\n"); AAAFreeMessage(&req); return AAA_ERROR_COMM; } exe = req->endtoendId; DBG("msg sent...\n"); return 0; }
int ServerConnection::handleRequest(AAAMessage* req) { switch (req->commandCode) { case AAA_CC_DWR: { // Device-Watchdog-Request DBG("Device-Watchdog-Request received\n"); AAAMessage* reply; if ( (reply=AAAInMessage(AAA_CC_DWA, AAA_APP_DIAMETER_COMMON_MSG))==NULL) { ERROR(M_NAME":handleRequest(): can't create new " "DWA message!\n"); return -1; } AAAMessageSetReply(reply); if (addOrigin(reply) || addResultCodeAVP(reply, AAA_SUCCESS)) { AAAFreeMessage(&reply); return AAA_ERROR_MESSAGE; } reply->endtoendId = req->endtoendId; reply->hopbyhopId = req->hopbyhopId; if(AAABuildMsgBuffer(reply) != AAA_ERR_SUCCESS) { ERROR( " sendRequest(): message buffer not created\n"); AAAFreeMessage(&reply); return AAA_ERROR_MESSAGE; } DBG("sending Device-Watchdog-Answer...\n"); int ret = tcp_send(conn.dia_conn, reply->buf.s, reply->buf.len); if (ret) { ERROR( " sendRequest(): could not send message\n"); closeConnection(); AAAFreeMessage(&reply); return AAA_ERROR_COMM; } AAAFreeMessage(&reply); return 0; }; break; case AAA_CC_DPR: { // Disconnect-Peer-Request string disconnect_cause = "UNKNOWN"; AAA_AVP* avp = req->avpList.head; while (avp) { if (avp->code == AVP_Disconnect_Cause) { switch((unsigned int)htonl(*((unsigned int*)avp->data.s))){ case 0:disconnect_cause = "REBOOTING"; break; case 1:disconnect_cause = "BUSY"; break; case 2:disconnect_cause = "DO_NOT_WANT_TO_TALK_TO_YOU"; break; } break; } avp=avp->next; } DBG("Disconnect-Peer-Request received. Cause: '%s'." " Sending Disconnect-Peer-Answer...\n", disconnect_cause.c_str()); AAAMessage* reply; if ( (reply=AAAInMessage(AAA_CC_DPA, AAA_APP_DIAMETER_COMMON_MSG))==NULL) { ERROR(M_NAME":handleRequest(): can't create new " "DPA message!\n"); return AAA_ERROR_MESSAGE; } AAAMessageSetReply(reply); // always send success (causing retry of requests on // different connection first, so race is unlikely) if (addOrigin(reply) || addResultCodeAVP(reply, AAA_SUCCESS)) { AAAFreeMessage(&reply); return AAA_ERROR_MESSAGE; } reply->endtoendId = req->endtoendId; reply->hopbyhopId = req->hopbyhopId; if(AAABuildMsgBuffer(reply) != AAA_ERR_SUCCESS) { ERROR( " sendRequest(): message buffer not created\n"); AAAFreeMessage(&reply); return AAA_ERROR_MESSAGE; } int ret = tcp_send(conn.dia_conn, reply->buf.s, reply->buf.len); if (ret) { ERROR( " sendRequest(): could not send message\n"); closeConnection(); AAAFreeMessage(&reply); return AAA_ERROR_COMM; } AAAFreeMessage(&reply); setRetryConnectLater(); return 0; }; break; default: { ERROR("ignoring unknown request with command code %i\n", req->commandCode); }; break; } return 0; }
void ServerConnection::openConnection() { DBG("init TCP connection\n"); if (conn.dia_conn) { ERROR("CRITICAL: trying to open new connection, while current one still" " opened.\n"); abort(); } conn.dia_conn = tcp_create_connection(server_name.c_str(), server_port, ca_file.c_str(), cert_file.c_str()); if (!conn.dia_conn) { ERROR("establishing connection to %s\n", server_name.c_str()); setRetryConnectLater(); return; } // send CER AAAMessage* cer; if ((cer=AAAInMessage(AAA_CC_CER, AAA_APP_DIAMETER_COMMON_MSG))==NULL) { ERROR(M_NAME":openConnection(): can't create new " "CER AAA message!\n"); conn.terminate(); setRetryConnectLater(); return; } if (addOrigin(cer) || addDataAVP(cer, AVP_Host_IP_Address, origin_ip_address, sizeof(origin_ip_address)) || addDataAVP(cer, AVP_Vendor_Id, (char*)&vendorID, sizeof(vendorID)) || addDataAVP(cer, AVP_Supported_Vendor_Id, (char*)&vendorID, sizeof(vendorID)) || addStringAVP(cer, AVP_Product_Name, product_name)) { ERROR("openConnection(): adding AVPs failed\n"); conn.terminate(); setRetryConnectLater(); return; } // supported applications AAA_AVP* vs_appid; if( (vs_appid=AAACreateAVP(AVP_Vendor_Specific_Application_Id, (AAA_AVPFlag)AAA_AVP_FLAG_NONE, 0, 0, 0, AVP_DONT_FREE_DATA)) == 0) { ERROR( M_NAME":openConnection(): creating AVP failed." " (no more free memory!)\n"); conn.terminate(); setRetryConnectLater(); return; } // feels like c coding... if (addGroupedAVP(vs_appid, AVP_Auth_Application_Id, (char*)&app_id, sizeof(app_id)) || addGroupedAVP(vs_appid, AVP_Vendor_Id, (char*)&vendorID, sizeof(vendorID)) || (AAAAddAVPToMessage(cer, vs_appid, 0) != AAA_ERR_SUCCESS) ) { ERROR( M_NAME":openConnection(): creating AVP failed." " (no more free memory!)\n"); conn.terminate(); setRetryConnectLater(); return; } #ifdef EXTRA_DEBUG AAAPrintMessage(cer); #endif conn.setIDs(cer); if(AAABuildMsgBuffer(cer) != AAA_ERR_SUCCESS) { ERROR( " openConnection(): message buffer not created\n"); AAAFreeMessage(&cer); return; } int ret = tcp_send(conn.dia_conn, cer->buf.s, cer->buf.len); if (ret) { ERROR( "openConnection(): could not send message\n"); conn.terminate(); setRetryConnectLater(); AAAFreeMessage(&cer); return; } AAAFreeMessage(&cer); unsigned int cea_receive_cnt = 3; while (true) { int res = tcp_recv_msg(conn.dia_conn, &conn.rb, CONNECT_CEA_REPLY_TIMEOUT, 0); if (res <= 0) { if (!res) { ERROR( " openConnection(): did not receive response (CEA).\n"); } else { ERROR( " openConnection(): error receiving response (CEA).\n"); } conn.terminate(); setRetryConnectLater(); return; } /* obtain the structure corresponding to the message */ AAAMessage* cea = AAATranslateMessage(conn.rb.buf, conn.rb.buf_len, 0); if(!cea) { ERROR( " openConnection(): could not decipher response (CEA).\n"); conn.terminate(); setRetryConnectLater(); return; } if (cea->commandCode == AAA_CC_CEA) { #ifdef EXTRA_DEBUG AAAPrintMessage(cea); #endif AAAFreeMessage(&cea); break; } AAAFreeMessage(&cea); if (!(cea_receive_cnt--)) { ERROR( " openConnection(): no CEA received.\n"); conn.terminate(); setRetryConnectLater(); return; } } DBG("Connection opened.\n"); open = true; }
SubRouteRequestPacket::SubRouteRequestPacket(const DriverPref* driverPref, const SubRouteVector* origs, const OrigDestInfoList* dests, const OrigDestInfoList* allDests, bool routeToOneDest, uint32 cutOff, int levelDelta, const DisturbanceVector* disturbances, bool calcCostSums, bool dontSendSubRoutes, const DisturbanceVector* infoModuleDists ) { mc2dbg4 << "SubRouteRequestPacket::SubRouteRequestPacket" << endl; setPriority(DEFAULT_PACKET_PRIO); // Calculate size of request // Origins and destinations // Do something about the listtype if ( driverPref->getVehicleRestriction() != ItemTypes::pedestrian ) { setListType(SubRouteListTypes::LOWER_LEVEL); } else { // Pedestrian setListType(SubRouteListTypes::LOWER_LEVEL_WALK); // Lower level walk } uint32 reqSize = SUBROUTE_REQUEST_HEADER_SIZE; // The number of subroutes int nbrSubRoutes = origs->getSize() + // Add the destinations for HIGHER_LEVEL too ((getListType() == SubRouteListTypes::HIGHER_LEVEL) ? dests->size() : 0); // Origin. Will probably be removed if ( origs != NULL && getListType() == SubRouteListTypes::HIGHER_LEVEL ) reqSize += origs->size() * ORIG_DEST_SIZE; // Destinations if ( dests != NULL ) reqSize += dests->size() * ORIG_DEST_SIZE; // Subroutes. for(uint32 i=0; i < origs->size() ; i++ ) { reqSize += SUB_ROUTE_SIZE + SUB_ROUTE_CONNECTION_SIZE * 1; } // Compensate for disturbances // Length reqSize += 4; if ( disturbances != NULL ) { reqSize += DISTURBANCE_SIZE*disturbances->size(); } reqSize += 4; if ( infoModuleDists != NULL ) { reqSize += 8 * infoModuleDists->size(); } if ( reqSize > getBufSize() ) { mc2dbg2 << "SubRouteRequestPacket - buffer too small reallocing" << endl; byte* temp = MAKE_UINT32_ALIGNED_BYTE_BUFFER( reqSize * 2); memcpy(temp, this->buffer, SUBROUTE_REQUEST_HEADER_SIZE); delete [] this->buffer; this->buffer = temp; this->bufSize = reqSize * 2; } // First request? Won't exactly work all the time... bool original = origs->front()->getPrevSubRouteID() == MAX_UINT32; if ( levelDelta == 1 ) { // Higher level routing - do some tricks setMapID( FIRST_OVERVIEWMAP_ID ); setListType(SubRouteListTypes::HIGHER_LEVEL); } //setOriginIP(leaderIP); //setOriginPort(leaderPort); setSubType(Packet::PACKETTYPE_SUBROUTEREQUEST); // Get mapid from one of the origins setMapID(origs->front()->getNextMapID() ); // Setting the extra vehicle to avoid toll roads. uint32 extraVehicle = 0; if ( driverPref->avoidTollRoads() ) { extraVehicle |= ItemTypes::avoidTollRoad; } if ( driverPref->avoidHighways() ) { extraVehicle |= ItemTypes::avoidHighway; } setVehicleRestrictions( driverPref->getVehicleRestriction() | extraVehicle ); setRoutingCosts(driverPref->getRoutingCosts()); setUseTurnCost(driverPref->useUturn()); setTime(driverPref->getTime()); setMinWaitTime(driverPref->getMinWaitTime()); // Some flags. setRouteToAll(! routeToOneDest ); setDontSendSubRoutes( dontSendSubRoutes ); setCalcCostSums( calcCostSums ); setRouteID(0); // Don't know what it should be. Seems to be the same // as the request id, but for the RouteReader. setCutOff(cutOff); setIsOriginalRequest(original); // Add the origins that belongs to this mapID and only the first time. setNbrOrigins(0); int pos = SUBROUTE_REQUEST_HEADER_SIZE; if ( original ) { for(uint32 i=0; i < origs->getSize(); i++) { const SubRoute* curSubRoute = origs->getSubRouteAt(i); // Destinations are origins in next route. const OrigDestInfo* orig = curSubRoute->getDestInfo(); addOrigin(*orig, pos); // addOrigin(curSubRoute->getNextMapID(), // curSubRoute->getDestNodeID(), // curSubRoute->getDestOffset(), // MAX_UINT32, // MAX_UINT32, // pos); } } // Add all destinations ( not allDests, they aren't used yet) setNbrDestinations(0); OrigDestInfoList::const_iterator it; it = dests->begin(); while ( it != dests->end() ) { addDestination(*it, pos); it++; } setNbrSubRoutes( nbrSubRoutes ); for (uint32 i = 0; i < origs->getSize(); i++) { SubRoute* subRoute = (*origs)[i]; if (subRoute != NULL) { addSubRoute(subRoute, pos); } } if ( getListType() == SubRouteListTypes::HIGHER_LEVEL ) { OrigDestInfoList::const_iterator it(dests->begin()); for(uint32 i=0; i < dests->size() ; ++i ) { SubRoute subRoute(*it, *it); ++it; // Add backward subroute for each destination. // The routemodule uses them as destinations later. addSubRoute(&subRoute, pos, false); } } addDisturbances(pos, disturbances); // Add info module disturbances using the more compact format. addInfoModDisturbances( pos, infoModuleDists ); setLength(pos); if ( true || pos > (int)reqSize || (reqSize - pos) > 65536 ) { mc2dbg2 << "SubRouteRequestPacket - calcSize = " << reqSize << "real size = " << pos << endl; } } // Constructor