// *************************************************************** // Function: AccessKeyGen.cpp // *************************************************************** #include "Main.h" //************************************ // Name: GenNumber // // Generates a number following access key rules. // // Parameters: // // Return: // - string form of a single digit //************************************ char GenNumber() { int num=5; while(num==5) { num=1+rand()%9; } char temp[3]; sprintf(temp, "%d", num); return temp[0]; } //************************************ // Name: GenLetter // // Generates a letter following access key rules. // // Parameters: // // Return: // - A letter following access key rules //************************************ char GenLetter() { char disallowed[12]={'A', 'E', 'I', 'O', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; char letter=0; while(true) { letter=65+rand()%25; bool allowed=true; for (int j=0; j<12; j++) { if (letter==disallowed[j]) { allowed=false; break; } } if (allowed) { return letter; } } } //************************************ // Name: console_generatekey // // Generates a Guild Wars access key. Puts it in the database. // // Parameters: // args[] - Command arguments // numArgs - Number of command arguments // adminConsole - Is this command being used from the admin console? // networkId - Caller's network id // // Return: // //************************************ void console_generatekey(char* args[], int numArgs, bool adminConsole, short networkId) { if (numArgs==1) { ConsoleWrite("Syntax: /generatekey {number of keys to generate}", adminConsole, networkId, 8); return; } srand((unsigned int)TimerGetTime()+atoi(args[1])); char key[26]; memset(key, 0, 26); for (int m=0; m0) { strcat(keyForm, "-"); } char te[5]; sprintf(te, "%c", key[i]); strcat(keyForm, te); } gCoreLog.debug(keyForm); char query[200]; sprintf(query, "INSERT INTO access_keys (AccessKey, KeyStatus) VALUES(\"%s\", 0)", key); gDatabase.Query(query, strlen(query)); } }