/* * mount in /dev a note file for the remote side to read. */ void lclnoteproc(int netfd) { Waitmsg *w; Note *np; int pfd[2]; int pid; if(pipe(pfd) < 0){ fprint(2, "cpu: can't start note proc: pipe: %r\n"); return; } /* new proc mounts and returns to start exportfs */ switch(pid = rfork(RFPROC|RFNAMEG|RFFDG|RFMEM)){ default: exportpid = pid; break; case -1: fprint(2, "cpu: can't start note proc: rfork: %r\n"); return; case 0: close(pfd[0]); if(mount(pfd[1], -1, "/dev", MBEFORE, "", 'M') < 0) fprint(2, "cpu: can't mount note proc: %r\n"); close(pfd[1]); return; } close(netfd); close(pfd[1]); /* new proc listens for note file system rpc's */ switch(rfork(RFPROC|RFNAMEG|RFMEM)){ case -1: fprint(2, "cpu: can't start note proc: rfork1: %r\n"); _exits(0); case 0: notefs(pfd[0]); _exits(0); } /* original proc waits for notes */ notify(catcher); w = nil; for(;;) { *notebuf = 0; free(w); w = wait(); if(w == nil) { if(*notebuf == 0) break; np = mallocz(sizeof(Note), 1); if(np != nil){ strcpy(np->msg, notebuf); lock(&nfs); if(nfs.nfirst == nil) nfs.nfirst = np; else nfs.nlast->next = np; nfs.nlast = np; unlock(&nfs); kick(pfd[0]); } unlock(&nfs); } else if(w->pid == exportpid) break; } if(w == nil) exits(nil); exits(0); /* exits(w->msg); */ }
int Irc::Session::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: connected(); break; case 1: welcomed(); break; case 2: reconnecting(); break; case 3: disconnected(); break; case 4: bufferAdded((*reinterpret_cast< Irc::Buffer*(*)>(_a[1]))); break; case 5: bufferRemoved((*reinterpret_cast< Irc::Buffer*(*)>(_a[1]))); break; case 6: capabilitiesListed((*reinterpret_cast< const QStringList(*)>(_a[1]))); break; case 7: capabilitiesAcked((*reinterpret_cast< const QStringList(*)>(_a[1]))); break; case 8: capabilitiesNotAcked((*reinterpret_cast< const QStringList(*)>(_a[1]))); break; case 9: msgJoined((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break; case 10: msgParted((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3]))); break; case 11: msgQuit((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break; case 12: msgNickChanged((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break; case 13: msgModeChanged((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3])),(*reinterpret_cast< const QString(*)>(_a[4]))); break; case 14: msgTopicChanged((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3]))); break; case 15: msgInvited((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3]))); break; case 16: msgKicked((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3])),(*reinterpret_cast< const QString(*)>(_a[4]))); break; case 17: msgMessageReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3]))); break; case 18: msgNoticeReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3]))); break; case 19: msgCtcpRequestReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break; case 20: msgCtcpReplyReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break; case 21: msgCtcpActionReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3]))); break; case 22: msgNumericMessageReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< uint(*)>(_a[2])),(*reinterpret_cast< const QStringList(*)>(_a[3]))); break; case 23: msgUnknownMessageReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QStringList(*)>(_a[2]))); break; case 24: connectToServer((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< quint16(*)>(_a[2]))); break; case 25: connectToServer((*reinterpret_cast< const QString(*)>(_a[1]))); break; case 26: connectToServer(); break; case 27: reconnectToServer(); break; case 28: disconnectFromServer(); break; case 29: { bool _r = raw((*reinterpret_cast< const QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 30: { bool _r = motd(); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 31: { bool _r = join((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 32: { bool _r = join((*reinterpret_cast< const QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 33: { bool _r = part((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 34: { bool _r = part((*reinterpret_cast< const QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 35: { bool _r = quit((*reinterpret_cast< const QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 36: { bool _r = quit(); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 37: { bool _r = names((*reinterpret_cast< const QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 38: { bool _r = list((*reinterpret_cast< const QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 39: { bool _r = list(); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 40: { bool _r = whois((*reinterpret_cast< const QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 41: { bool _r = whowas((*reinterpret_cast< const QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 42: { bool _r = mode((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 43: { bool _r = mode((*reinterpret_cast< const QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 44: { bool _r = topic((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 45: { bool _r = topic((*reinterpret_cast< const QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 46: { bool _r = invite((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 47: { bool _r = kick((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 48: { bool _r = kick((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 49: { bool _r = message((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 50: { bool _r = notice((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 51: { bool _r = ctcpAction((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 52: { bool _r = ctcpRequest((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 53: { bool _r = ctcpReply((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 54: requestCapabilities((*reinterpret_cast< const QStringList(*)>(_a[1]))); break; case 55: clearCapabilities(); break; case 56: { bool _r = sendRaw((*reinterpret_cast< const QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 57: { bool _r = cmdJoin((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 58: { bool _r = cmdJoin((*reinterpret_cast< const QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 59: { bool _r = cmdPart((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 60: { bool _r = cmdPart((*reinterpret_cast< const QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 61: { bool _r = cmdQuit((*reinterpret_cast< const QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 62: { bool _r = cmdQuit(); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 63: { bool _r = cmdNames((*reinterpret_cast< const QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 64: { bool _r = cmdList((*reinterpret_cast< const QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 65: { bool _r = cmdList(); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 66: { bool _r = cmdWhois((*reinterpret_cast< const QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 67: { bool _r = cmdMode((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 68: { bool _r = cmdMode((*reinterpret_cast< const QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 69: { bool _r = cmdTopic((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 70: { bool _r = cmdTopic((*reinterpret_cast< const QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 71: { bool _r = cmdInvite((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 72: { bool _r = cmdKick((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 73: { bool _r = cmdKick((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 74: { bool _r = cmdMessage((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 75: { bool _r = cmdNotice((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 76: { bool _r = cmdCtcpAction((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 77: { bool _r = cmdCtcpRequest((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 78: { bool _r = cmdCtcpReply((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 79: d_func()->_q_connected(); break; case 80: d_func()->_q_disconnected(); break; case 81: d_func()->_q_reconnect(); break; case 82: d_func()->_q_error(); break; case 83: d_func()->_q_state((*reinterpret_cast< QAbstractSocket::SocketState(*)>(_a[1]))); break; case 84: d_func()->_q_readData(); break; case 85: d_func()->_q_joined((*reinterpret_cast< const QString(*)>(_a[1]))); break; case 86: d_func()->_q_parted((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break; case 87: d_func()->_q_quit((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break; case 88: d_func()->_q_nickChanged((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break; case 89: d_func()->_q_modeChanged((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3]))); break; case 90: d_func()->_q_topicChanged((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break; case 91: d_func()->_q_invited((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3]))); break; case 92: d_func()->_q_kicked((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3]))); break; case 93: d_func()->_q_messageReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break; case 94: d_func()->_q_noticeReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break; case 95: d_func()->_q_ctcpRequestReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break; case 96: d_func()->_q_ctcpReplyReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break; case 97: d_func()->_q_ctcpActionReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break; case 98: d_func()->_q_numericMessageReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< uint(*)>(_a[2])),(*reinterpret_cast< const QStringList(*)>(_a[3]))); break; case 99: d_func()->_q_unknownMessageReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QStringList(*)>(_a[2]))); break; default: ; } _id -= 100; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< QStringList*>(_v) = autoJoinChannels(); break; case 1: *reinterpret_cast< int*>(_v) = autoReconnectDelay(); break; case 2: *reinterpret_cast< QByteArray*>(_v) = encoding(); break; case 3: *reinterpret_cast< QString*>(_v) = host(); break; case 4: *reinterpret_cast< QString*>(_v) = ident(); break; case 5: *reinterpret_cast< QString*>(_v) = nick(); break; case 6: *reinterpret_cast<int*>(_v) = QFlag(options()); break; case 7: *reinterpret_cast< QString*>(_v) = password(); break; case 8: *reinterpret_cast< quint16*>(_v) = port(); break; case 9: *reinterpret_cast< QString*>(_v) = realName(); break; case 10: *reinterpret_cast< QStringList*>(_v) = supportedCapabilities(); break; case 11: *reinterpret_cast< QStringList*>(_v) = enabledCapabilities(); break; } _id -= 12; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setAutoJoinChannels(*reinterpret_cast< QStringList*>(_v)); break; case 1: setAutoReconnectDelay(*reinterpret_cast< int*>(_v)); break; case 2: setEncoding(*reinterpret_cast< QByteArray*>(_v)); break; case 3: setHost(*reinterpret_cast< QString*>(_v)); break; case 4: setIdent(*reinterpret_cast< QString*>(_v)); break; case 5: setNick(*reinterpret_cast< QString*>(_v)); break; case 6: setOptions(QFlag(*reinterpret_cast<int*>(_v))); break; case 7: setPassword(*reinterpret_cast< QString*>(_v)); break; case 8: setPort(*reinterpret_cast< quint16*>(_v)); break; case 9: setRealName(*reinterpret_cast< QString*>(_v)); break; } _id -= 12; } else if (_c == QMetaObject::ResetProperty) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 12; } #endif // QT_NO_PROPERTIES return _id; }
void AI_main(struct RoboAI *ai, struct blob *blobs, void *state) { /************************************************************************* You will be working with a state-based AI. You are free to determine how many states there will be, what each state will represent, and what actions the robot will perform based on the state as well as the state transitions. You must *FULLY* document your state representation in the report Here two states are defined: State 0,100,200 - Before robot ID has taken place (this state is the initial state, or is the result of pressing 'r' to reset the AI) State 1,101,201 - State after robot ID has taken place. At this point the AI knows where the robot is, as well as where the opponent and ball are (if visible on the playfield) Relevant UI keyboard commands: 'r' - reset the AI. Will set AI state to zero and re-initialize the AI data structure. 't' - Toggle the AI routine (i.e. start/stop calls to AI_main() ). 'o' - Robot immediate all-stop! - do not allow your NXT to get damaged! ** Do not change the behaviour of the robot ID routine ** **************************************************************************/ if (ai->st.state == 0 || ai->st.state == 100 || ai->st.state == 200) // Initial set up - find own, ball, and opponent blobs { // Carry out self id process. fprintf(stderr, "Initial state, self-id in progress...\n"); id_bot(ai, blobs); if ((ai->st.state % 100) != 0) // The id_bot() routine will change the AI state to initial state + 1 { // if robot identification is successful. if (ai->st.self->cx[0] >= 512) ai->st.side = 1; else ai->st.side = 0; all_stop(); clear_motion_flags(ai); fprintf(stderr, "Self-ID complete. Current position: (%f,%f), current heading: [%f, %f], AI state=%d\n", ai->st.self->cx[0], ai->st.self->cy[0], ai->st.self->mx, ai->st.self->my, ai->st.state); } } else { /**************************************************************************** TO DO: You will need to replace this 'catch-all' code with actual program logic to have the robot do its work depending on its current state. After id_bot() has successfully completed its work, the state should be 1 - if the bot is in SOCCER mode 101 - if the bot is in PENALTY mode 201 - if the bot is in CHASE mode Your AI code needs to handle these states and their associated state transitions which will determine the robot's behaviour for each mode. *****************************************************************************/ // track_agents(ai,blobs); // Currently, does nothing but endlessly track // fprintf(stderr,"Just trackin'!\n"); // bot, opponent, and ball. switch(ai->st.state){ case 101: kick(); sleep(2); break; case 201: chase(ai); break; } } }
void Forward() { static int g_loop = 0; getMaxball(); PID(); if (g_diff > 45 || g_diff < -45) turn(20); else { g_integral == 0; if(g_no == 0) { if(g_ball[0] > 300) { g_dist[0] = getPing(0); g_dist[1] = getPing(1); g_dist[3] = getPing(3); if(g_dist[1] >= 35 && g_dist[2] >= 35) { kick(); moveAngle4ch( 78 , 0 , 0); } else if (g_dist[0] < 12) { if(g_dist[1] < 40) { turn(80); delay(100); } else if (g_dist[3] < 40) { turn(-80); delay(100); } } } else moveAngle4ch( 78 , 0 , 0 ); } else if(g_no == 1) { g_dist[1] = getPing(1); if (g_dist[1] < 10) moveAngle4ch (78 , 0 , 0); else if(g_ball[1] > 500) moveAngle4ch( 78 , 0 , 255 ); else moveAngle4ch( 78 , 0 , 315); } else if(g_no == 2) { if(g_ball[2] > 500) moveAngle4ch( 78 , 0 , 180); else moveAngle4ch( 78 , 0 , 270); } else if(g_no == 3 ) { moveAngle4ch( 78 , 0 , 135 ); } else if(g_no == 4 ) { g_dist[1] = getPing(1); g_dist[3] = getPing(3); if (g_dist[1] > g_dist[3]) moveAngle4ch( 78 , 0 , 270 ); else moveAngle4ch(78 , 0 , 90 ); } else if(g_no == 5) { if (g_ball[5] > 500) moveAngle4ch( 78 , 0 , 255 ); else moveAngle4ch( 78 , 0 , 135); } else if(g_no == 6) { if(g_ball[6] > 500) moveAngle4ch( 78 , 0 , 180 ); else moveAngle4ch(78, 0 ,90); } else if(g_no == 7) { g_dist[3] = getPing(3); if (g_dist[3] < 10) moveAngle4ch (78 , 0 , 0); else if (g_ball[7] > 500) moveAngle4ch( 78 , 0 , 105); else moveAngle4ch ( 78 , 0 , 45); } else goHome(); } g_loop++; }
void Irc::parse(QString raw) { if (raw.startsWith(':')) raw = raw.right(raw.length() - 1); #ifdef COLOR_WIPE QString xraw; int len = 0; int olen = raw.length(); // dirty but useful color removal code do { do { if ( raw [len] == '\003' ) { // color, veo muuucho color len += 2; if ( raw [len].isNumber() ) len++; if ( raw [len] == ',' && raw [len+1].isDigit() ) { // color, veo aúuuun más color len += 2; if ( raw [len].isNumber() ) len++; } } else if ( raw [len] == '\002' || raw [len] == '\026' || raw [len] == '\035' ) // blablalba len++; } while ( raw [len] == '\003' || raw [len] == '\002'|| raw [len] == '\026'|| raw [len] == '\035' ); // esto es una guarrada pero evita varios control codes consecutivos xraw.append(raw[len]); len++; } while( len < olen ); raw = xraw; #endif QStringList matrix = raw.split(' '); if( matrix[0] == "PING" ) { // Recibido ping, pongoneamos. sendData("PONG " + matrix[1]); emit PingPong(); } else if ( matrix[0] == "ERROR" ) { // error de conexion, whichever emit connError(raw.right(raw.length() - 7)); //quita el "ERROR :" del principio y deja el msj limpio } else if ( matrix[1] == "PRIVMSG" || matrix[1] == "NOTICE" ) { QString nick = matrix[0].left(matrix[0].indexOf('!')); QString message = raw.right((raw.length() - 2) - raw.indexOf(" :")); QString mask = matrix[0].mid(matrix[0].indexOf('!') + 1,(matrix[0].indexOf(" PRIVMSG") - nick.length())); if ( matrix[1] == "PRIVMSG" ) { if ( matrix[2].startsWith("#") ) { // mensaje de canal if ( message.startsWith("\001") ) // /ctcp if ( message.startsWith("\001ACTION ")) // me emit chanme ( nick, mask, matrix[2], message.right((message.length() - 8)) ); else emit chanctcp ( nick, mask, matrix[2], message.right((message.length() - 1)) ); else emit chanmsg ( nick, mask, matrix[2], message ); } else { // mensaje en privado if ( message.startsWith("\001") ) // /me if ( message.startsWith("\001ACTION ")) // me emit queryme ( nick, mask, message.right((message.length() - 8)) ); else emit queryctcp ( nick, mask, message.right((message.length() - 1)) ); else emit querymsg ( nick, mask, message ); } } else if ( matrix[1] == "NOTICE" ) { if ( matrix[2].startsWith("#") ) { // notice en canal emit channotice ( nick, mask, matrix[2], message ); } else { // notice en privado emit querynotice ( nick, mask, message ); } } } else if ( matrix[1] == "JOIN" ) { //join a un canal QString nick = matrix[0].left(matrix[0].indexOf('!')); QString mask = matrix[0].mid(matrix[0].indexOf('!') + 1,(matrix[0].indexOf(" JOIN") - nick.length())); if( matrix[2].startsWith(':') ) emit join(nick,mask,matrix[2].right( matrix[2].length() -1 )); else emit join(nick,mask,matrix[2]); } else if ( matrix[1] == "PART" || matrix[1] == "QUIT" ) { //handled together QString message = "", chan = ""; if (raw.indexOf(" :") != -1) message = raw.right((raw.length() - 2) - raw.indexOf(" :")); QString nick = matrix[0].left(matrix[0].indexOf('!')); QString mask = matrix[0].mid(matrix[0].indexOf('!') + 1,(matrix[0].indexOf(" PART") - nick.length())); if ( matrix[1] == "PART" ) { QString chan = raw.right((raw.length() - 1) - raw.indexOf(" #")); chan = chan.left(chan.indexOf(" :")); QString mask = matrix[0].mid(matrix[0].indexOf('!') + 1,(matrix[0].indexOf(" PART") - nick.length())); emit part(nick,mask,chan,message); } else if ( matrix[1] == "QUIT" ) { QString mask = matrix[0].mid(matrix[0].indexOf('!') + 1,(matrix[0].indexOf(" QUIT") - nick.length())); emit quit(nick,mask,message); } } else if ( matrix[1] == "NICK" ) { QString nick = matrix[0].left(matrix[0].indexOf('!')); QString mask = matrix[0].mid(matrix[0].indexOf('!') + 1,(matrix[0].indexOf(" NICK") - nick.length())); QString newnick = raw.right((raw.length() - 2) - raw.indexOf(" :")); if (newnick == ownNick) emit ownNickChange(newnick); emit nickChange(nick,mask,newnick); } else if ( matrix[1] == "MODE" ) { // cambio de modo, pero no sé si es de usuario o canal. if ( matrix[2].startsWith('#') ) { // c mode QString nick = matrix[0].left(matrix[0].indexOf('!')); QString mask = matrix[0].mid(matrix[0].indexOf('!') + 1,(matrix[0].indexOf(" MODE") - nick.length())); QString chan = matrix[2]; QString mode = raw.right((raw.length() - raw.indexOf(" #")) - chan.length() - 2); emit modeChange(nick,mask,chan,mode); } else { // u mode if( matrix[3].startsWith(':') ) emit umodeChange(matrix[0],matrix[2],matrix[3].right( matrix[3].length() -1 )); else emit umodeChange(matrix[0],matrix[2],matrix[3]); } } else if ( matrix[1] == "KICK" ) { // expulsión del canal if ( matrix[2].startsWith('#') ) { // c mode QString nick = matrix[0].left(matrix[0].indexOf('!')); QString mask = matrix[0].mid(matrix[0].indexOf('!') + 1,(matrix[0].indexOf(" KICK") - nick.length())); QString chan = matrix[2]; QString kicked = matrix[3]; QString message; if (raw.indexOf(" :") != -1) message = raw.right((raw.length() - 2) - raw.indexOf(" :")); emit kick(nick,mask,chan,kicked,message); } else // u mode emit umodeChange(matrix[0],matrix[2],raw.right((raw.length() - 2) - raw.indexOf(" :"))); } bool isInt; int code_msg = matrix[1].toInt( &isInt ); if( isInt ) { switch ( code_msg ) { case 001: // me es útil, así sé con qué nick entro xD emit ownNickChange(matrix[2]); ownNick = matrix[2]; if (!chans.isEmpty()) { sendData("JOIN ",true); sendData(chans); } status = STATUS_IDLE; emit signedIn(); break; case 254: // número de canales formados emit totalChans(matrix[3]); case 321: // chanlist begin handleChanlist(false); break; case 322: // chanlist handleChanlist(matrix[3],matrix[4],raw.right((raw.length() - 2) - raw.indexOf(" :"))); break; case 323: // chanlist end handleChanlist(true); break; case 332: //topic emit topic(matrix[3],raw.right((raw.length() - 2) - raw.indexOf(" :"))); break; case 333: //topic timestamp emit topicTime(matrix[3],matrix[4],matrix[5]); break; case 353: // names emit names(matrix[4], raw.right((raw.length() - 2) - raw.indexOf(" :"))); break; case 366: // fin de /names emit namesEnd(matrix[3]); break; case 372: // texto de motd emit motd( raw.right((raw.length() - 2) - raw.indexOf(" :"))); break; case 375: // inicio de motd emit motdStart( raw.right((raw.length() - 2) - raw.indexOf(" :"))); break; case 376: // fin de motd emit motdEnd( raw.right((raw.length() - 2) - raw.indexOf(" :"))); break; case 433: // nick en uso! getNewRandomNick(); break; case 471: qDebug() << matrix[3] << "Cannot join channel (+l)"; break; case 473: qDebug() << matrix[3] << "Cannot join channel (+i)"; break; case 474: qDebug() << matrix[3] << "Cannot join channel (+b)"; break; case 475: qDebug() << matrix[3] << "Cannot join channel (+k)"; break; default: //qDebug() << "Numeric NO MANEJADO!" << matrix[1] << endl; break; } } }
void ServerImpl::onClientInfo( CL_NetGameConnection *p_conn, const CL_NetGameEvent &p_event ) { ClientInfo clientInfo; clientInfo.parseEvent(p_event); // check the version if (clientInfo.getProtocolVersion().getMajor() != PROTOCOL_VERSION_MAJOR) { cl_log_event( LOG_EVENT, "unsupported protocol version for player '%2'", reinterpret_cast<unsigned>(p_conn) ); // send goodbye kick(p_conn, GR_UNSUPPORTED_PROTOCOL_VERSION); return; } // check name availability bool nameAvailable = true; TConnectionPlayerPair pair; foreach (pair, m_connections) { if (pair.second.m_name == clientInfo.getName()) { nameAvailable = false; } } if (!nameAvailable) { cl_log_event( LOG_EVENT, "name '%1' already in use for player '%2'", clientInfo.getName(), reinterpret_cast<unsigned>(p_conn) ); // send goodbye kick(p_conn, GR_NAME_ALREADY_IN_USE); return; } // set the name and inform all m_connections[p_conn].m_name = clientInfo.getName(); cl_log_event( LOG_EVENT, "'%1' is now known as '%2', sending gamestate...", reinterpret_cast<unsigned>(p_conn), clientInfo.getName() ); PlayerJoined playerJoined; playerJoined.setName(clientInfo.getName()); sendToAll(playerJoined.buildEvent(), p_conn); // send the gamestate const GameState gamestate = prepareGameState(); send(p_conn, gamestate.buildEvent()); m_connections[p_conn].m_gameStateSent = true; }
//------------------------------------------------------------------------------------- Proxy::~Proxy() { Baseapp::getSingleton().decProxicesCount(); kick(); SAFE_RELEASE(pProxyForwarder_); }
void BasicPlayer::joystickPlay() { if ( !isJoystickLive ) { isJoystickLive = setupJoystick(); if ( !isJoystickLive ) exit(1); } // initialize moving Vectors int move_x; int move_y; int move_lr; int move_ud; // event loop SDL_Event event; if(SDL_PollEvent(&event)) { switch (event.type) { //axis aligned movements of agent (all Events tested on BTP-C036) case SDL_JOYAXISMOTION: switch(event.jaxis.axis){ // slow but precise move left-right case 0: move_x= SDL_JoystickGetAxis(joystick,0); move_lr= move_x/500; drive(Vector3f(move_lr,0,0)); cout<<"axis 0\n"; break; // slow but precise move up-down case 1: move_y= SDL_JoystickGetAxis(joystick,1); move_ud= -(move_y/500); drive(Vector3f(0,move_ud,0)); cout<<"axis 1\n"; break; // fast but unprecise move up-down case 2: move_y= SDL_JoystickGetAxis(joystick,2); move_ud= -(move_y/100); drive(Vector3f(0,move_ud,0)); cout<<"axis 2\n"; break; // fast but unprecise move left-right case 3: move_x= SDL_JoystickGetAxis(joystick,3); move_lr= move_x/100; drive(Vector3f(move_lr,0,0)); cout<<"axis 3\n"; break; default: drive(Vector3f(0,0,0)); cout<< "axis motion default\n"; break; } break; // events which occur if certain buttons are pressed case SDL_JOYBUTTONDOWN: switch(event.jbutton.button) { //low kick case 2: kick(90,20); LOG( 99,"low kick"); break; //normal kick case 3: kick(90,50); LOG( 99,"normal kick"); break; //hard kick case 5: kick(90,70); LOG( 99,"hard kick"); break; //jumping; is not functional yet /* case 0: drive(Vector3f(0,0,10)); break;*/ default: LOG( 99,"kick default"); break; } break; default: cout << "event default\n"; break; } } }
void Player::autoKick() { if (!isLoggedIn()) kick(); }
void HWChatWidget::onKick() { QListWidgetItem * curritem = chatNicks->currentItem(); if (curritem) emit kick(curritem->text()); }