1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
#include "qr2regkeys.h"
#include "../common/gsStringUtil.h"
#include "../common/gsDebug.h"
#ifdef __MWERKS__ // CodeWarrior requires prototypes
void qr2_register_keyW(int keyid, const unsigned short *key);
void qr2_register_keyA(int keyid, const char *key);
#endif
const char *qr2_registered_key_list[MAX_REGISTERED_KEYS] =
{
"", //0 is reserved
"hostname", //1
"gamename", //2
"gamever", //3
"hostport", //4
"mapname", //5
"gametype", //6
"gamevariant", //7
"numplayers", //8
"numteams", //9
"maxplayers", //10
"gamemode", //11
"teamplay", //12
"fraglimit", //13
"teamfraglimit",//14
"timeelapsed", //15
"timelimit", //16
"roundtime", //17
"roundelapsed", //18
"password", //19
"groupid", //20
"player_", //21
"score_", //22
"skill_", //23
"ping_", //24
"team_", //25
"deaths_", //26
"pid_", //27
"team_t", //28
"score_t", //29
"nn_groupid", //30
// Query From Master Only keys
"country", //31
"region" //32
};
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Keep a list of the unicode keys we've allocated internally so that we can free
// them when qr2 is shutdown
typedef struct QR2KeyListNodeS
{
char* mKeyData;
struct QR2KeyListNodeS* mNextKey;
} QR2KeyListNode;
typedef struct QR2KeyListS
{
struct QR2KeyListNodeS* mHead;
} QR2KeyList;
static QR2KeyList qr2_internal_key_list = { NULL };
void qr2_internal_key_list_append(char* theKey)
{
QR2KeyListNode* aNewNode;
assert(theKey != NULL);
// Init the new node
aNewNode = (QR2KeyListNode*)gsimalloc(sizeof(QR2KeyListNode));
aNewNode->mKeyData = theKey;
aNewNode->mNextKey = NULL;
// Check for a NULL head
if (qr2_internal_key_list.mHead == NULL)
qr2_internal_key_list.mHead = aNewNode;
else
{
// Find the end of the list and append this node
QR2KeyListNode* aInsertPlace = qr2_internal_key_list.mHead;
while(aInsertPlace->mNextKey != NULL)
aInsertPlace = aInsertPlace->mNextKey;
aInsertPlace->mNextKey = aNewNode;
}
}
void qr2_internal_key_list_free()
{
QR2KeyListNode* aNodeToFree;
QR2KeyListNode* aNextNode;
// Free the nodes
aNodeToFree = qr2_internal_key_list.mHead;
while (aNodeToFree != NULL)
{
aNextNode = aNodeToFree->mNextKey; // Get a ptr to the next node (or will be lost)
gsifree(aNodeToFree->mKeyData); // free the string we allocated in qr2_register_keyW
gsifree(aNodeToFree); // free the current node
aNodeToFree = aNextNode; // set the current node to the next node
}
// Initialize the list back to NULL
qr2_internal_key_list.mHead = NULL;
}
gsi_bool qr2_internal_is_master_only_key(const char * keyname)
{
if (strcmp(keyname,qr2_registered_key_list[COUNTRY_KEY]) == 0 ||
strcmp(keyname,qr2_registered_key_list[REGION_KEY]) == 0)
return gsi_true;
return gsi_false;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void qr2_register_keyA(int keyid, const char *key)
{
gsDebugFormat(GSIDebugCat_QR2, GSIDebugType_Misc, GSIDebugLevel_StackTrace,
"qr2_register_keyA()\r\n");
// Verify the key range
if (keyid < NUM_RESERVED_KEYS || keyid > MAX_REGISTERED_KEYS)
{
gsDebugFormat(GSIDebugCat_QR2, GSIDebugType_Misc, GSIDebugLevel_WarmError,
"Attempted to register invalid key %d - %s\r\n", keyid, key);
return;
}
gsDebugFormat(GSIDebugCat_QR2, GSIDebugType_Misc, GSIDebugLevel_Comment,
"Registered key %d - %s\r\n", keyid, key);
qr2_registered_key_list[keyid] = key;
}
void qr2_register_keyW(int keyid, const unsigned short *key)
{
char* key_A = NULL;
gsDebugFormat(GSIDebugCat_QR2, GSIDebugType_Misc, GSIDebugLevel_StackTrace,
"qr2_register_keyW()\r\n");
// Create UTF8 copy
key_A = UCS2ToUTF8StringAlloc(key);
// Register the ascii version
qr2_register_keyA(keyid, key_A);
// Keep track of the unicode version so we can delete it later
qr2_internal_key_list_append(key_A);
}
|