long ExtObject::eGetMessages(LPVAL params, ExpReturn& ret) { if(taggedMessages.IsEmpty()) return ret.ReturnString(pRuntime, ""); int start = clamp(params[0].GetInt() - 1, 0, taggedMessages.GetUpperBound()); int end = clamp(params[1].GetInt() - 1, 0, taggedMessages.GetUpperBound()); return ret.ReturnString(pRuntime, getMessages(start, end)); }
docstring const translateIfPossible(docstring const & name, std::string const & language) { if (support::isAscii(name) && !name.empty()) // Probably from a standard configuration file, try to // translate return getMessages(language).get(to_ascii(name)); else // This must be from a user defined configuration file. We // cannot translate this, since gettext accepts only ascii // keys. return name; }
long ExtObject::eGetMessagesByTags(LPVAL params, ExpReturn &ret) { if(taggedMessages.IsEmpty()) return ret.ReturnString(pRuntime, ""); int start = clamp(params[0].GetInt() - 1, 0, taggedMessages.GetUpperBound()); int end = clamp(params[1].GetInt() - 1, 0, taggedMessages.GetUpperBound()); CStringList tags; Messenger::splitTags(params[2].GetString(), tags); return ret.ReturnString(pRuntime, getMessages(start, end, &tags)); }
ChatClient::ChatClient(QWidget *parent) : QWidget(parent) { ui.setupUi(this); nickAccepted = false; //Setup the timer timer = new QTimer(); timer->setInterval(1000); //TODO activate this when your ready (i.e. you're ready to write the //slot associated with it! QWidget::connect(timer,SIGNAL(timeout()),this,SLOT(getMessages())); lastMessageNo = 0; }
void FanucAdapter::gatherDeviceData() { if (!mConnected) connect(); else { getPositions(); getAxisLoad(); getSpindleLoad(); getStatus(); getMessages(); getMacros(); getPMC(); getCounts(); getToolData(); } }
void writeThread(const QDir& output_dir, const std::string& a_thread, int gmt_offset, sqlite::connection& con) { std::locale loc(std::locale::classic(), new boost::posix_time::time_facet("%Y/%m/%d %H:%M")); // seems Facebook does not record seconds info std::stringstream ss; ss.imbue(loc); QString filename = output_dir.filePath(QString::fromStdString(a_thread+".txt")); std::ofstream f(filename.toLocal8Bit().constData()); sqlite::query getMessages(con, "SELECT timestamp,contentIndex,user,content FROM messages WHERE thread=? ORDER BY timestamp ASC, contentIndex DESC"); // facebook put newer messages first getMessages.bind(1, a_thread); boost::shared_ptr<sqlite::result> result2 = getMessages.get_result(); while(result2->next_row()) { int timestamp = result2->get_int(0); std::string user = result2->get_string(2); std::string content = result2->get_string(3); ss << boost::posix_time::from_time_t(timestamp + gmt_offset * 3600); f << ss.str() << "," << user << "," << content << "\n"; ss.str(std::string()); } f.close(); }
QString KGpgImport::getImportMessage() const { return getImportMessage(getMessages()); }
QStringList KGpgImport::getImportedIds(const int reason) const { return getImportedIds(getMessages(), reason); }
void decideHunterMove(HunterView gameState) { int turn = giveMeTurnNum(gameState); messages = malloc(sizeof(PlayerMessage)*turn); getMessages(gameState,messages); int current_player = whoAmI(gameState); srand(time(NULL)); //initialises current_leader global variable int current_round = giveMeTheRound(gameState); int current_rank = getRank(gameState, current_player, current_round); PlayerMessage message = ""; int leader_trail[TRAIL_SIZE]; giveMeTheTrail(gameState,current_leader,leader_trail); printf("current leader is %d\n",current_leader); printf("LT->"); int j; for (j=0;j<TRAIL_SIZE;j++){ printf("%d->",leader_trail[j]); } printf("x\n"); int drac_trail[TRAIL_SIZE]; giveMeTheTrail(gameState,PLAYER_DRACULA,drac_trail); printf("DT->"); int m; for (m=0;m<TRAIL_SIZE;m++){ printf("%d->",drac_trail[m]); } printf("x\n"); int move; char *moveTo; printf("check %d %d\n",current_round,current_leader); if (current_round == 0) { if(current_player == PLAYER_LORD_GODALMING) {move = PLAYER1_START_POS;} else if(current_player == PLAYER_DR_SEWARD) {move = PLAYER2_START_POS;} else if(current_player == PLAYER_VAN_HELSING) {move = PLAYER3_START_POS;} else if(current_player == PLAYER_MINA_HARKER) {move = PLAYER4_START_POS;} else printf("I am noone..\n"); makeMessageFollower(gameState, current_player, message); } else if (current_player == current_leader) { printf("I am the leader\n"); move = makeRandomMove2(gameState,current_player); moveTo = idToAbbrev(move); registerBestPlay(moveTo,message); move = makeLeaderMove(gameState,message); } else { printf("I am a follower"); move = makeRandomMove2(gameState,current_player); moveTo = idToAbbrev(move); registerBestPlay(moveTo,message); printf(" and I am making a move\n"); move = makeFollowerMove(gameState, current_player, current_rank); makeMessageFollower(gameState, current_player, message); } printf("move is %d\n",move); moveTo = idToAbbrev(move); registerBestPlay(moveTo,message); }
/* main: Runs the server. Taken from: http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html#simpleserver As recomended returns EXIT_FAILURE on failure */ int main(int argc, char *argv[]) { int sockfd; struct addrinfo hints, *servinfo, *p; int rv; int recvPoll; int numbytes; int i; /*Counter*/ int timeout, windowSize, windowStart; struct pollfd clientPoll; packet currentPacket; struct sockaddr_in clientAddr; socklen_t addr_len; bool windowIsOK; memset(&clientAddr, 0, sizeof(clientAddr)); memset(&hints, 0, sizeof hints); hints.ai_family = AF_UNSPEC; /* set to AF_INET to force IPv4 */ hints.ai_socktype = SOCK_DGRAM; hints.ai_flags = AI_PASSIVE; /* use my IP */ numbytes = 0; if (argc != 5) { fprintf(stderr,"Incorrect Usage, use: gobackSend host port timeout(ms) windowSize \n"); exit(1); } windowStart = 0; timeout = atoi(argv[3]); windowSize = atoi(argv[4]); /*From Beej*/ if ((rv = getaddrinfo(argv[1], argv[2], &hints, &servinfo)) != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv)); return 1; } /* loop through all the results and bind to the first we can */ for(p = servinfo; p != NULL; p = p->ai_next) { if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) { perror("Sender: socket"); continue; } break; } clientPoll.fd = sockfd; clientPoll.events = POLLIN; if (p == NULL) { fprintf(stderr, "Sender: failed to bind socket\n"); return 2; } /*TODO: Get messages from user, about 10 to send*/ /*TODO: Send message+header one at a time and resend any bad messages*/ freeaddrinfo(servinfo); /*Connection Made, grab initial messages*/ getMessages(); while(1) { /*Reset for when window size is smaller than what the user defines*/ windowSize = atoi(argv[4]); addr_len = sizeof(clientAddr); if(windowStart >= packetOffset) { /*Get more Messages!*/ printf("More Messages Required, please enter more messages!\n"); getMessages(); } /*If our number of packets to be sent is less than our windowsize, adjust our current window*/ if(packetOffset - windowStart < windowSize) { printf("Number of Packets is smaller than window, sending incomplete window\n"); windowSize = packetOffset - windowStart; } printf("Sending Window, with packet %d to %d \n", windowStart, windowStart + windowSize - 1); /*Send Window*/ for(i = windowStart; i < (windowStart + windowSize); i++) { /*Interesting bug, it wont print this until later unless I use a \n character.*/ printf("Sending Message #%d...\n", i); if((numbytes = sendto(sockfd, (char*)&packetArray[i], sizeof(packetArray[i]), 0, p->ai_addr, p->ai_addrlen)) == -1) { perror("sendto"); exit(1); } /*Poll Recv for Response on timeout*/ recvPoll = poll(&clientPoll, 1, timeout); /*Timeout*/ if(recvPoll == 0) { printf("Timed Out.\n"); } /*Error*/ else if(recvPoll == -1) { perror("POLLIN"); exit(1); } /*Else we gucci*/ else { printf("Response!\n"); if ((numbytes = recvfrom(sockfd, (char*)¤tPacket, sizeof(currentPacket), 0, (struct sockaddr *)p->ai_addr, (socklen_t *)&addr_len)) == -1) { perror("revfrom"); exit(1); } if(currentPacket.packetNumber != i) { printf("***********************\n"); printf("* ERROR: OUT OF ORDER *\n"); printf("* Got: %d Expected: %d *\n", currentPacket.packetNumber, i); printf("***********************\n"); /*break;*/ } printf("---------------------------\n"); printf("#%d\t %sAck:%d\n", currentPacket.packetNumber, currentPacket.message, currentPacket.ack); printf("---------------------------\n"); /*Set ackArray to match what was recieved*/ packetAck[currentPacket.packetNumber] = currentPacket.ack; } } windowIsOK = false; for(i = windowStart; i < (windowStart + windowSize); i++) { if(packetAck[i] == true) windowIsOK = true; else { windowIsOK = false; break; } } if(windowIsOK == true) { printf("Window is okay! Sending next window!\n"); windowStart += windowSize; } else { printf("Window is NOT okay. Resending.\n"); for(i = windowStart; i < (windowStart + windowSize); i++) { packetAck[i] = false; } } printf("====================\n"); } close(sockfd); return 0; }
return 0; } int handle_ipaws(xmpp_conn_t * const conn __attribute__((unused)), void * const userdata ) { struct soap* soap = (struct soap*) userdata; static char tmpstr[32] = { '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' }; time_t* tmp_timet = NULL; time_t derp = last_update - 130; strftime(tmpstr,32,"%Y-%m-%dT%H:%M:%S",gmtime(&derp)); sprintf(tmpstr + strlen(tmpstr), "%+03d:%02d", 0,0); derp = time(NULL); printf("Fetching since %s\n", tmpstr); messages_t* msgs = getMessages(soap, tmpstr); if (msgs) { last_update = derp; for ( unsigned int i = 0; i < msgs->size; i++ ) { if ( strncmp(msgs->ids[i], "NOMESSAGEFOUND", 14) == 0 ) continue; if ( g_hash_table_lookup_extended(table, msgs->ids[i], NULL, NULL) ) continue; sendAlert(conn, ctx, msgs->alerts[i], msgs->ids[i]); tmp_timet = malloc(sizeof(time_t)); *tmp_timet = *(msgs->expires[i]); g_hash_table_insert(table, strdup(msgs->ids[i]), tmp_timet); tmp_timet = NULL; }
int main() { int i; HunterView hv; printf("Test basic empty initialisation\n"); PlayerMessage messages1[] = {}; hv = newHunterView("", messages1); assert(whoAmI(hv) == PLAYER_LORD_GODALMING); assert(giveMeTheRound(hv) == 0); assert(howHealthyIs(hv,PLAYER_DR_SEWARD) == GAME_START_HUNTER_LIFE_POINTS); assert(howHealthyIs(hv,PLAYER_DRACULA) == GAME_START_BLOOD_POINTS); assert(giveMeTheScore(hv) == GAME_START_SCORE); assert(whereIs(hv,PLAYER_LORD_GODALMING) == UNKNOWN_LOCATION); printf("passed\n"); disposeHunterView(hv); printf("Test for Dracula trail and basic functions\n"); PlayerMessage messages2[] = {"Hello","Rubbish","Stuff","","Mwahahah"}; hv = newHunterView("GST.... SAO.... HZU.... MBB.... DC?....", messages2); int turn = giveMeTurnNum(hv); PlayerMessage messages[turn]; getMessages(hv,messages); printf("beginning messages\n"); int j; for (j=0;j<turn;j++) { printf("%s\n",messages[j]); } assert(whoAmI(hv) == PLAYER_LORD_GODALMING); assert(giveMeTheRound(hv) == 1); assert(whereIs(hv,PLAYER_LORD_GODALMING) == STRASBOURG); assert(whereIs(hv,PLAYER_DR_SEWARD) == ATLANTIC_OCEAN); assert(whereIs(hv,PLAYER_VAN_HELSING) == ZURICH); assert(whereIs(hv,PLAYER_MINA_HARKER) == BAY_OF_BISCAY); assert(whereIs(hv,PLAYER_DRACULA) == CITY_UNKNOWN); assert(howHealthyIs(hv,PLAYER_DRACULA) == GAME_START_BLOOD_POINTS); printf("passed\n"); disposeHunterView(hv); printf("Test for encountering Dracula and hunter history\n"); PlayerMessage messages3[] = {"Hello","Rubbish","Stuff","","Mwahahah","Aha!"}; hv = newHunterView("GST.... SAO.... HCD.... MAO.... DGE.... GGED...", messages3); assert(whereIs(hv,PLAYER_DRACULA) == GENEVA); assert(howHealthyIs(hv,PLAYER_LORD_GODALMING) == 5); assert(howHealthyIs(hv,PLAYER_DRACULA) == 30); assert(whereIs(hv,PLAYER_LORD_GODALMING) == GENEVA); LocationID history[TRAIL_SIZE]; giveMeTheTrail(hv,PLAYER_DRACULA,history); assert(history[0] == GENEVA); assert(history[1] == UNKNOWN_LOCATION); giveMeTheTrail(hv,PLAYER_LORD_GODALMING,history); assert(history[0] == GENEVA); assert(history[1] == STRASBOURG); assert(history[2] == UNKNOWN_LOCATION); giveMeTheTrail(hv,PLAYER_DR_SEWARD,history); assert(history[0] == ATLANTIC_OCEAN); assert(history[1] == UNKNOWN_LOCATION); printf("passed\n"); disposeHunterView(hv); printf("Test for Dracula doubling back at sea, and losing blood points (Hunter View)\n"); PlayerMessage messages4[] = {"Hello","Rubbish","Stuff","","Mwahahah","Aha!","","","","Back I go"}; hv = newHunterView("GGE.... SGE.... HGE.... MGE.... DS?.... " "GST.... SST.... HST.... MST.... DD1....", messages4); assert(whereIs(hv,PLAYER_DRACULA) == DOUBLE_BACK_1); giveMeTheTrail(hv,PLAYER_DRACULA,history); assert(history[0] == DOUBLE_BACK_1); assert(history[1] == SEA_UNKNOWN); assert(howHealthyIs(hv,PLAYER_DRACULA) == GAME_START_BLOOD_POINTS - 4); assert(whoAmI(hv) == 0); printf("passed\n"); disposeHunterView(hv); printf("Test for connections\n"); int size, seen[NUM_MAP_LOCATIONS], *edges; printf("Checking Galatz road connections\n"); PlayerMessage messages5[] = {"Gone to Galatz"}; hv = newHunterView("GGA....", messages5); edges = whereCanTheyGo(hv,&size,PLAYER_LORD_GODALMING,1,0,0); memset(seen, 0, NUM_MAP_LOCATIONS*sizeof(int)); for (i = 0; i< size ; i++) seen[edges[i]] = 1; assert(size == 5); assert(seen[GALATZ]); assert(seen[CONSTANTA]); assert(seen[BUCHAREST]); assert(seen[KLAUSENBURG]); assert(seen[CASTLE_DRACULA]); free(edges); disposeHunterView(hv); printf("Checking Ionian Sea sea connections\n"); PlayerMessage messages6[] = {"Sailing the Ionian"}; hv = newHunterView("GIO....", messages6); edges = whereCanTheyGo(hv,&size,PLAYER_LORD_GODALMING,0,0,1); memset(seen, 0, NUM_MAP_LOCATIONS*sizeof(int)); for (i = 0; i < size; i++) seen[edges[i]] = 1; assert(size == 7); assert(seen[IONIAN_SEA]); assert(seen[BLACK_SEA]); assert(seen[ADRIATIC_SEA]); assert(seen[TYRRHENIAN_SEA]); assert(seen[ATHENS]); assert(seen[VALONA]); assert(seen[SALONICA]); free(edges); disposeHunterView(hv); printf("Checking Athens rail connections (none)\n"); PlayerMessage messages7[] = {"Leaving Athens by train"}; hv = newHunterView("GAT....", messages7); edges = whereCanTheyGo(hv,&size,PLAYER_LORD_GODALMING,0,1,0); assert(size == 1); assert(edges[0] == ATHENS); free(edges); disposeHunterView(hv); printf("passed\n"); return 0; }