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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
/*
gpiUnique.c
GameSpy Presence SDK
Dan "Mr. Pants" Schoenblum
Copyright 1999-2007 GameSpy Industries, Inc
devsupport@gamespy.com
***********************************************************************
Please see the GameSpy Presence SDK documentation for more information
**********************************************************************/
//INCLUDES
//////////
#include "gpi.h"
//FUNCTIONS
///////////
static GPResult
gpiSendRegisterUniqueNick(
GPConnection * connection,
const char uniquenick[GP_UNIQUENICK_LEN],
const char cdkey[GP_CDKEY_LEN],
int operationid
)
{
GPIConnection * iconnection = (GPIConnection*)*connection;
gpiAppendStringToBuffer(connection, &iconnection->outputBuffer, "\\registernick\\\\sesskey\\");
gpiAppendIntToBuffer(connection, &iconnection->outputBuffer, iconnection->sessKey);
gpiAppendStringToBuffer(connection, &iconnection->outputBuffer, "\\uniquenick\\");
gpiAppendStringToBuffer(connection, &iconnection->outputBuffer, uniquenick);
if(cdkey)
{
gpiAppendStringToBuffer(connection, &iconnection->outputBuffer, "\\cdkey\\");
gpiAppendStringToBuffer(connection, &iconnection->outputBuffer, cdkey);
}
gpiAppendStringToBuffer(connection, &iconnection->outputBuffer, "\\partnerid\\");
gpiAppendIntToBuffer(connection, &iconnection->outputBuffer, iconnection->partnerID);
gpiAppendStringToBuffer(connection, &iconnection->outputBuffer, "\\id\\");
gpiAppendIntToBuffer(connection, &iconnection->outputBuffer, operationid);
gpiAppendStringToBuffer(connection, &iconnection->outputBuffer, "\\final\\");
return GP_NO_ERROR;
}
GPResult gpiRegisterUniqueNick(
GPConnection * connection,
const char uniquenick[GP_UNIQUENICK_LEN],
const char cdkey[GP_CDKEY_LEN],
GPEnum blocking,
GPCallback callback,
void * param
)
{
GPIOperation * operation = NULL;
GPResult result;
// Add the operation.
/////////////////////
CHECK_RESULT(gpiAddOperation(connection, GPI_REGISTER_UNIQUENICK, NULL, &operation, blocking, callback, param));
// Send a request for info.
///////////////////////////
result = gpiSendRegisterUniqueNick(connection, uniquenick, cdkey, operation->id);
CHECK_RESULT(result);
// Process it if blocking.
//////////////////////////
if(blocking)
{
result = gpiProcess(connection, operation->id);
CHECK_RESULT(result);
}
return GP_NO_ERROR;
}
GPResult gpiProcessRegisterUniqueNick(
GPConnection * connection,
GPIOperation * operation,
const char * input
)
{
GPICallback callback;
// Check for an error.
//////////////////////
if(gpiCheckForError(connection, input, GPITrue))
return GP_SERVER_ERROR;
// This should be \rn\.
///////////////////////
if(strncmp(input, "\\rn\\", 4) != 0)
CallbackFatalError(connection, GP_NETWORK_ERROR, GP_PARSE, "Unexpected data was received from the server.");
// Call the callback.
/////////////////////
callback = operation->callback;
if(callback.callback != NULL)
{
GPRegisterUniqueNickResponseArg * arg;
arg = (GPRegisterUniqueNickResponseArg *)gsimalloc(sizeof(GPRegisterUniqueNickResponseArg));
if(arg == NULL)
Error(connection, GP_MEMORY_ERROR, "Out of memory.");
arg->result = GP_NO_ERROR;
CHECK_RESULT(gpiAddCallback(connection, callback, arg, operation, 0));
}
// This operation is complete.
//////////////////////////////
gpiRemoveOperation(connection, operation);
return GP_NO_ERROR;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Registration of cdKey now offered separately from uniquenick
static GPResult
gpiSendRegisterCdKey(
GPConnection * connection,
const char cdkey[GP_CDKEY_LEN],
int operationid
)
{
GPIConnection * iconnection = (GPIConnection*)*connection;
// Encrypt the cdkey (xor with random values)
const int useAlternateEncoding = 1;
char cdkeyxor[GP_CDKEY_LEN];
char cdkeyenc[GP_CDKEYENC_LEN];
int cdkeylen = (int)strlen(cdkey);
int i=0;
Util_RandSeed((unsigned long)GP_XOR_SEED);
for (i=0; i < cdkeylen; i++)
{
// XOR each character with the next rand
char aRand = (char)Util_RandInt(0, 0xFF);
cdkeyxor[i] = (char)(cdkey[i] ^ aRand);
}
cdkeyxor[i] = '\0';
// Base 64 it (printable chars only)
B64Encode(cdkeyxor, cdkeyenc, (int)cdkeylen, useAlternateEncoding);
gpiAppendStringToBuffer(connection, &iconnection->outputBuffer, "\\registercdkey\\\\sesskey\\");
gpiAppendIntToBuffer(connection, &iconnection->outputBuffer, iconnection->sessKey);
gpiAppendStringToBuffer(connection, &iconnection->outputBuffer, "\\cdkeyenc\\");
gpiAppendStringToBuffer(connection, &iconnection->outputBuffer, cdkeyenc);
// gpiAppendStringToBuffer(connection, &iconnection->outputBuffer, "\\partnerid\\");
// gpiAppendIntToBuffer(connection, &iconnection->outputBuffer, iconnection->partnerID);
gpiAppendStringToBuffer(connection, &iconnection->outputBuffer, "\\id\\");
gpiAppendIntToBuffer(connection, &iconnection->outputBuffer, operationid);
gpiAppendStringToBuffer(connection, &iconnection->outputBuffer, "\\final\\");
return GP_NO_ERROR;
}
GPResult gpiRegisterCdKey(
GPConnection * connection,
const char cdkey[GP_CDKEY_LEN],
GPEnum blocking,
GPCallback callback,
void * param
)
{
GPIOperation * operation = NULL;
GPResult result;
// Add the operation.
/////////////////////
CHECK_RESULT(gpiAddOperation(connection, GPI_REGISTER_CDKEY, NULL, &operation, blocking, callback, param));
// Send a request for info.
///////////////////////////
result = gpiSendRegisterCdKey(connection, cdkey, operation->id);
CHECK_RESULT(result);
// Process it if blocking.
//////////////////////////
if(blocking)
{
result = gpiProcess(connection, operation->id);
CHECK_RESULT(result);
}
return GP_NO_ERROR;
}
GPResult gpiProcessRegisterCdKey(
GPConnection * connection,
GPIOperation * operation,
const char * input
)
{
GPICallback callback;
// Check for an error.
//////////////////////
if(gpiCheckForError(connection, input, GPITrue))
return GP_SERVER_ERROR;
// This should be \rc\.
///////////////////////
if(strncmp(input, "\\rc\\", 4) != 0)
CallbackFatalError(connection, GP_NETWORK_ERROR, GP_PARSE, "Unexpected data was received from the server.");
// Call the callback.
/////////////////////
callback = operation->callback;
if(callback.callback != NULL)
{
GPRegisterCdKeyResponseArg * arg;
arg = (GPRegisterCdKeyResponseArg *)gsimalloc(sizeof(GPRegisterCdKeyResponseArg));
if(arg == NULL)
Error(connection, GP_MEMORY_ERROR, "Out of memory.");
arg->result = GP_NO_ERROR;
CHECK_RESULT(gpiAddCallback(connection, callback, arg, operation, 0));
}
// This operation is complete.
//////////////////////////////
gpiRemoveOperation(connection, operation);
return GP_NO_ERROR;
}
|