int Reader(CommandBase* commands [], int num_commands, int argc, const char** argv) { std::vector<const char*> inputs; CommandBase* last_command = NULL; CommandHelp help_command(commands,num_commands); int command_count = 0; bool command_chosen = false; for(int i=1; i<argc; i++) { double tmp; if(argv[i][0] == '-' && !string_is_double(argv[i],tmp)) { //command if(string_is_double(argv[i],tmp)) command_chosen = false; //check for help queries first if(0 == strcmp("help",&argv[i][1])) { if(last_command != NULL) { int res = DoCommand(last_command,inputs); if(res <= 0) return res; } last_command = &help_command; command_count++; command_chosen = true; } //search through rest of commands for(int k=0; k<num_commands && !command_chosen; k++) { if(0 == strcmp(commands[k]->Name(),&argv[i][1])) { //we've found a command if(last_command != NULL) { int res = DoCommand(last_command,inputs); if(res <= 0) return res; } last_command = commands[k]; command_chosen = true; command_count++; } } if(!command_chosen) { printf("Unknown command %s\n", argv[i]); PrintCommands(commands, num_commands); return -1; } } else { //add an argument inputs.push_back(argv[i]); command_chosen = false; } } if(command_count == 0) { if(inputs.size() > 0) cout<<"Some stray elements were given on the command line"<<endl; PrintCommands(commands, num_commands); } else { assert(last_command != NULL); int res = DoCommand(last_command,inputs); if(res <= 0) return res; } return 0; }
void DrawAvailableUnits(Level *lvl, UnitList *PDUL) { PrintLevelStatus(lvl); PrintCommands(); if (lvl->id == 0) { Tutorial(); } attron(A_BOLD); attron(A_UNDERLINE); mvprintw(45,50,"Unit Selection:"); attroff(A_UNDERLINE); mvprintw(47,6,"\tSelection Code\tPrice\tSpeed HP Damage Symbol"); attroff(A_BOLD); Unit *tempUnit; /*cost,id,speed,health,damage,immunity */ for (int i = 0; i < PDUL->size; ++i) { tempUnit = UnitPeek(i,PDUL); //assuming unitfile is in order of id -> add loop if (lvl->available[i] == UnitID(tempUnit)) { mvprintw(48+i,6,"\t\t%c\t$%d\t %d %d %d ",UnitID(tempUnit), tempUnit->cost, tempUnit->speed+1, tempUnit->health, tempUnit->damage); attron(COLOR_PAIR(UnitID(tempUnit)-96)); printw("%d",tempUnit->health); attroff(COLOR_PAIR(UnitID(tempUnit)-96)); } } }
void DrawMenu(void) { PrintTitle(0,30); PrintOutline(); PrintSpawnQueue(); PrintCommands(); PrintUnitSelection(); }
void ShowHelpMenu_handler(edict_t *ent, int option) { if (option == 666) { closemenu(ent); return; } else { switch(option) { case 10: ShowBasicsMenu(ent); return; case 20: ShowCommandsMenu(ent); return; case 30: PrintCommands(ent); return; case 40: ShowRuneTypes(ent); return; case 50: ShowItemsHelpMenu(ent); return; case 60: ShowTradeHelpMenu(ent); return; case 70: ShowVoteHelpMenu(ent); return; case 80: ShowModeHelpMenu(ent); return; } } }
int main() { printf("TODO Rename RackspaceConsole.\nAdd RackspaceServerManager, uses CloudClient to monitor load, reboot lost servers.\n"); #if OPEN_SSL_CLIENT_SUPPORT!=1 printf("RakNet must be built with OPEN_SSL_CLIENT_SUPPORT"); return 1; #endif RakNet::Rackspace rackspaceApi; RakNet::TCPInterface tcpInterface; DisplayHTMLPage callback; rackspaceApi.AddEventCallback(&callback); tcpInterface.Start(0, 0, 1); if (!Authenticate(&rackspaceApi, &tcpInterface)) { return 1; } //rackspaceApi.ListImages(); PrintCommands(); RakNet::SystemAddress systemAddress; RakNet::Packet *packet; while (1) { for (packet=tcpInterface.Receive(); packet; tcpInterface.DeallocatePacket(packet), packet=tcpInterface.Receive()) { rackspaceApi.OnReceive(packet); } RakNet::SystemAddress lostConnectionAddress = tcpInterface.HasLostConnection(); if (lostConnectionAddress!=RakNet::UNASSIGNED_SYSTEM_ADDRESS) rackspaceApi.OnClosedConnection(lostConnectionAddress); if (kbhit()) { printf("Command: "); char command[128]; Gets(command, sizeof(command)); if (stricmp(command,"Help")==0) { PrintCommands(); } else if (stricmp(command,"Quit")==0) { break; } else if (stricmp(command,"Authenticate")==0) { Authenticate(&rackspaceApi, &tcpInterface); } else if (stricmp(command,"ListServers")==0) { rackspaceApi.ListServers(); } else if (stricmp(command,"ListServersWithDetails")==0) { rackspaceApi.ListServersWithDetails(); } else if (stricmp(command,"CreateServer")==0) { RakNet::RakString name; printf("Enter server name: "); Gets(command, sizeof(command)); name=command; RakNet::RakString imageId; printf("Enter imageId: "); Gets(command, sizeof(command)); imageId=command; RakNet::RakString flavorId; printf("Enter flavorId: "); Gets(command, sizeof(command)); flavorId=command; rackspaceApi.CreateServer(name, imageId, flavorId); } else if (stricmp(command,"GetServerDetails")==0) { printf("Enter server id: "); Gets(command, sizeof(command)); rackspaceApi.GetServerDetails(command); } else if (stricmp(command,"UpdateServerNameOrPassword")==0) { RakNet::RakString serverId; printf("Enter server id: "); Gets(command, sizeof(command)); serverId=command; RakNet::RakString newName; printf("Enter newName: "); Gets(command, sizeof(command)); newName=command; RakNet::RakString newPassword; printf("Enter newPassword: "******"DeleteServer")==0) { printf("Enter server id: "); Gets(command, sizeof(command)); rackspaceApi.DeleteServer(command); } else if (stricmp(command,"ListServerAddresses")==0) { printf("Enter server id: "); Gets(command, sizeof(command)); rackspaceApi.ListServerAddresses(command); } else if (stricmp(command,"ShareServerAddress")==0) { RakNet::RakString serverId; printf("Enter server id: "); Gets(command, sizeof(command)); serverId=command; RakNet::RakString serverAddress; printf("Enter server serverAddress: "); Gets(command, sizeof(command)); serverAddress=command; rackspaceApi.ShareServerAddress(serverId, serverAddress); } else if (stricmp(command,"DeleteServerAddress")==0) { RakNet::RakString serverId; printf("Enter server id: "); Gets(command, sizeof(command)); serverId=command; RakNet::RakString serverAddress; printf("Enter server serverAddress: "); Gets(command, sizeof(command)); serverAddress=command; rackspaceApi.DeleteServerAddress(serverId, serverAddress); } else if (stricmp(command,"RebootServer")==0) { RakNet::RakString serverId; printf("Enter server id: "); Gets(command, sizeof(command)); serverId=command; RakNet::RakString rebootType; printf("Enter rebootType: "); Gets(command, sizeof(command)); rebootType=command; rackspaceApi.RebootServer(serverId,rebootType); } else if (stricmp(command,"RebuildServer")==0) { RakNet::RakString serverId; printf("Enter server id: "); Gets(command, sizeof(command)); serverId=command; RakNet::RakString imageId; printf("Enter imageId: "); Gets(command, sizeof(command)); imageId=command; rackspaceApi.RebuildServer(serverId,imageId); } else if (stricmp(command,"ResizeServer")==0) { RakNet::RakString serverId; printf("Enter server id: "); Gets(command, sizeof(command)); serverId=command; RakNet::RakString flavorId; printf("Enter flavorId: "); Gets(command, sizeof(command)); flavorId=command; rackspaceApi.ResizeServer(serverId,flavorId); } else if (stricmp(command,"ConfirmResizedServer")==0) { printf("Enter server id: "); Gets(command, sizeof(command)); rackspaceApi.ConfirmResizedServer(command); } else if (stricmp(command,"RevertResizedServer")==0) { printf("Enter server id: "); Gets(command, sizeof(command)); rackspaceApi.RevertResizedServer(command); } else if (stricmp(command,"ListFlavors")==0) { rackspaceApi.ListFlavors(); } else if (stricmp(command,"GetFlavorDetails")==0) { printf("Enter flavor id: "); Gets(command, sizeof(command)); rackspaceApi.GetFlavorDetails(command); } else if (stricmp(command,"ListImages")==0) { rackspaceApi.ListImages(); } else if (stricmp(command,"CreateImage")==0) { RakNet::RakString serverId; printf("Enter server id: "); Gets(command, sizeof(command)); serverId=command; RakNet::RakString imageName; printf("Enter imageName: "); Gets(command, sizeof(command)); imageName=command; rackspaceApi.CreateImage(serverId,imageName); } else if (stricmp(command,"GetImageDetails")==0) { printf("Enter image id: "); Gets(command, sizeof(command)); rackspaceApi.GetImageDetails(command); } else if (stricmp(command,"DeleteImage")==0) { printf("Enter image id: "); Gets(command, sizeof(command)); rackspaceApi.DeleteImage(command); } else if (stricmp(command,"ListSharedIPGroups")==0) { rackspaceApi.ListSharedIPGroups(); } else if (stricmp(command,"ListSharedIPGroupsWithDetails")==0) { rackspaceApi.ListSharedIPGroupsWithDetails(); } else if (stricmp(command,"CreateSharedIPGroup")==0) { rackspaceApi.CreateSharedIPGroup("testSharedIPGroup",""); } else if (stricmp(command,"GetSharedIPGroupDetails")==0) { printf("Enter group id: "); Gets(command, sizeof(command)); rackspaceApi.GetSharedIPGroupDetails(command); } else if (stricmp(command,"DeleteSharedIPGroup")==0) { printf("Enter group id: "); Gets(command, sizeof(command)); rackspaceApi.DeleteSharedIPGroup(command); } else { printf("Unknown command. Type 'help' for help.\n"); } } RakSleep(30); } return 0; }
int main() { printf("This sample creates two Lobby2Clients.\n"); printf("They both connect to the server and performs queued operations on startup."); printf("(RANKING AND CLANS NOT YET DONE).\n"); printf("Difficulty: Advanced\n\n"); RakNet::Lobby2ResultCodeDescription::Validate(); /// Do all these operations in this order once we are logged in. /// This is for easier testing. /// This plan will create the database, register two users, and log them both in executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_System_CreateDatabase), _FILE_AND_LINE_ ); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_System_CreateTitle), _FILE_AND_LINE_ ); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_CDKey_Add), _FILE_AND_LINE_ ); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_System_RegisterProfanity), _FILE_AND_LINE_ ); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Client_RegisterAccount), _FILE_AND_LINE_ ); executionPlan.Push(AutoExecutionPlanNode(1, RakNet::L2MID_Client_RegisterAccount), _FILE_AND_LINE_ ); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_System_SetEmailAddressValidated), _FILE_AND_LINE_ ); executionPlan.Push(AutoExecutionPlanNode(1, RakNet::L2MID_System_SetEmailAddressValidated), _FILE_AND_LINE_ ); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Client_Login), _FILE_AND_LINE_ ); executionPlan.Push(AutoExecutionPlanNode(1, RakNet::L2MID_Client_Login), _FILE_AND_LINE_ ); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Emails_Send), _FILE_AND_LINE_ ); executionPlan.Push(AutoExecutionPlanNode(1, RakNet::L2MID_Emails_Get), _FILE_AND_LINE_ ); // /// Create 2 clans // executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Clans_Create), _FILE_AND_LINE_ ); // executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Clans_Create), _FILE_AND_LINE_ ); // // Invite to both // executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Clans_SendJoinInvitation), _FILE_AND_LINE_ ); // executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Clans_SendJoinInvitation), _FILE_AND_LINE_ ); // executionPlan.Push(AutoExecutionPlanNode(1, RakNet::L2MID_Clans_RejectJoinInvitation), _FILE_AND_LINE_ ); // // Download invitations this clan has sent // executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Clans_DownloadInvitationList), _FILE_AND_LINE_ ); /* executionPlan.Push(AutoExecutionPlanNode(1, RakNet::L2MID_Client_SetPresence), _FILE_AND_LINE_ ); executionPlan.Push(AutoExecutionPlanNode(1, RakNet::L2MID_Client_GetAccountDetails), _FILE_AND_LINE_ ); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Client_PerTitleIntegerStorage), _FILE_AND_LINE_ ); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Client_PerTitleIntegerStorage), _FILE_AND_LINE_ ); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Client_StartIgnore), _FILE_AND_LINE_ ); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Client_GetIgnoreList), _FILE_AND_LINE_ ); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Friends_SendInvite), _FILE_AND_LINE_); executionPlan.Push(AutoExecutionPlanNode(1, RakNet::L2MID_Friends_AcceptInvite), _FILE_AND_LINE_); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Ranking_SubmitMatch)); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Ranking_SubmitMatch)); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Ranking_UpdateRating)); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Ranking_GetRating)); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Ranking_WipeRatings)); */ // executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Clans_Create), _FILE_AND_LINE_ ); // executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Clans_Get), _FILE_AND_LINE_ ); /* executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Clans_SetProperties)); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Clans_SetMyMemberProperties)); */ /* executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Clans_SendJoinInvitation)); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Clans_WithdrawJoinInvitation)); executionPlan.Push(AutoExecutionPlanNode(1, RakNet::L2MID_Clans_DownloadInvitationList)); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Clans_SendJoinInvitation)); executionPlan.Push(AutoExecutionPlanNode(1, RakNet::L2MID_Clans_RejectJoinInvitation)); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Clans_SendJoinInvitation)); executionPlan.Push(AutoExecutionPlanNode(1, RakNet::L2MID_Clans_AcceptJoinInvitation)); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Clans_SetSubleaderStatus)); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Clans_SetMemberRank)); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Clans_GrantLeader)); */ /* executionPlan.Push(AutoExecutionPlanNode(1, RakNet::L2MID_Clans_SendJoinRequest)); executionPlan.Push(AutoExecutionPlanNode(1, RakNet::L2MID_Clans_WithdrawJoinRequest)); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Clans_AcceptJoinRequest)); */ // executionPlan.Push(AutoExecutionPlanNode(1, RakNet::L2MID_Clans_SendJoinRequest)); // executionPlan.Push(AutoExecutionPlanNode(1, RakNet::L2MID_Clans_DownloadRequestList)); // TODO - test from here /* executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Clans_RejectJoinRequest)); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Clans_AcceptJoinRequest)); executionPlan.Push(AutoExecutionPlanNode(1, RakNet::L2MID_Clans_SendJoinRequest)); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Clans_AcceptJoinRequest)); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Clans_KickAndBlacklistUser)); executionPlan.Push(AutoExecutionPlanNode(1, RakNet::L2MID_Clans_SendJoinRequest)); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Clans_GetBlacklist)); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Clans_UnblacklistUser)); executionPlan.Push(AutoExecutionPlanNode(1, RakNet::L2MID_Clans_SendJoinRequest)); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Clans_AcceptJoinRequest)); executionPlan.Push(AutoExecutionPlanNode(0, RakNet::L2MID_Clans_GetMembers)); */ /* // TODO L2MID_Clans_CreateBoard, L2MID_Clans_DestroyBoard, L2MID_Clans_CreateNewTopic, L2MID_Clans_ReplyToTopic, L2MID_Clans_RemovePost, L2MID_Clans_GetBoards, L2MID_Clans_GetTopics, L2MID_Clans_GetPosts, */ char ip[64], serverPort[30], clientPort[30]; int i; for (i=0; i < NUM_CONNECTIONS; i++) rakPeer[i]=RakNet::RakPeerInterface::GetInstance(); puts("Enter the rakPeer1 port to listen on"); clientPort[0]=0; RakNet::SocketDescriptor socketDescriptor(atoi(clientPort),0); Gets(clientPort,sizeof(clientPort)); if (clientPort[0]==0) strcpy(clientPort, "0"); puts("Enter IP to connect to");; ip[0]=0; Gets(ip,sizeof(ip)); if (ip[0]==0) strcpy(ip, "127.0.0.1"); puts("Enter the port to connect to"); serverPort[0]=0; Gets(serverPort,sizeof(serverPort)); if (serverPort[0]==0) strcpy(serverPort, "61111"); for (i=0; i < NUM_CONNECTIONS; i++) { rakPeer[i]->Startup(1,&socketDescriptor, 1); rakPeer[i]->Connect(ip, atoi(serverPort), 0,0); rakPeer[i]->AttachPlugin(&lobby2Client[i]); lobby2Client[i].SetMessageFactory(&messageFactory); lobby2Client[i].SetCallbackInterface(&callback[i]); testUserName[i]=RakNet::RakString("user%i", i); } RakNet::Packet *packet; // Loop for input while (1) { for (i=0; i < NUM_CONNECTIONS; i++) { RakNet::RakPeerInterface *peer = rakPeer[i]; for (packet=peer->Receive(); packet; peer->DeallocatePacket(packet), packet=peer->Receive()) { switch (packet->data[0]) { case ID_DISCONNECTION_NOTIFICATION: // Connection lost normally printf("ID_DISCONNECTION_NOTIFICATION\n"); break; case ID_ALREADY_CONNECTED: // Connection lost normally printf("ID_ALREADY_CONNECTED\n"); break; case ID_CONNECTION_BANNED: // Banned from this server printf("We are banned from this server.\n"); break; case ID_CONNECTION_ATTEMPT_FAILED: printf("Connection attempt failed\n"); break; case ID_NO_FREE_INCOMING_CONNECTIONS: // Sorry, the server is full. I don't do anything here but // A real app should tell the user printf("ID_NO_FREE_INCOMING_CONNECTIONS\n"); break; case ID_INVALID_PASSWORD: printf("ID_INVALID_PASSWORD\n"); break; case ID_CONNECTION_LOST: // Couldn't deliver a reliable packet - i.e. the other system was abnormally // terminated printf("ID_CONNECTION_LOST\n"); break; case ID_CONNECTION_REQUEST_ACCEPTED: // This tells the rakPeer1 they have connected printf("ID_CONNECTION_REQUEST_ACCEPTED\n"); int j; for (j=0; j < NUM_CONNECTIONS; j++) lobby2Client[j].SetServerAddress(packet->systemAddress); if (i==NUM_CONNECTIONS-1) { PrintCommands(&messageFactory); printf("Enter instance number 1 to %i followed by command number.\n", NUM_CONNECTIONS); if (executionPlan.Size()) { /// Execute the first command now that both clients have connected. AutoExecutionPlanNode aepn = executionPlan.Pop(); ExecuteCommand(aepn.operation, RakNet::RakString("user%i", aepn.instanceNumber), aepn.instanceNumber); } } break; case ID_LOBBY2_SERVER_ERROR: { RakNet::BitStream bs(packet->data,packet->length,false); bs.IgnoreBytes(2); // ID_LOBBY2_SERVER_ERROR and error code printf("ID_LOBBY2_SERVER_ERROR: "); if (packet->data[1]==RakNet::L2SE_UNKNOWN_MESSAGE_ID) { unsigned int messageId; bs.Read(messageId); printf("L2SE_UNKNOWN_MESSAGE_ID %i", messageId); } else printf("Unknown"); printf("\n"); } break; } } } // This sleep keeps RakNet responsive RakSleep(30); if (kbhit()) { char ch = getch(); if (ch <= '0' || ch > '9') { printf("Bad instance number\n"); continue; } int instanceNumber = ch - 1 - '0'; if (instanceNumber >= NUM_CONNECTIONS) { printf("Enter between 1 and %i to pick the instance of RakPeer to run\n", 1+NUM_CONNECTIONS); continue; } printf("Enter message number or 'quit' to quit.\n"); char str[128]; Gets(str, sizeof(str)); if (_stricmp(str, "quit")==0) { printf("Quitting.\n"); break; } else { int command = atoi(str); if (command <=0 || command > RakNet::L2MID_COUNT) { printf("Invalid message index %i. Commands:\n", command); PrintCommands(&messageFactory); } else { ExecuteCommand((RakNet::Lobby2MessageID)(command-1), RakNet::RakString("user%i", instanceNumber), instanceNumber); } } } } for (i=0; i < NUM_CONNECTIONS; i++) RakNet::RakPeerInterface::DestroyInstance(rakPeer[i]); return 0; }