Пример #1
0
GPResult
gpiSendOrBufferChar(
  GPConnection * connection,
  GPIPeer_st peer,
  char c
)
{
	//GPIBool closed;
	//int sent;
/*
	assert(peer->outputBuffer.buffer != NULL);

	// Only try to send if the buffer is empty and there are no messages.
	/////////////////////////////////////////////////////////////////////
	if(!(peer->outputBuffer.len - peer->outputBuffer.pos) && !ArrayLength(peer->messages))
	{
		CHECK_RESULT(gpiSendData(connection, peer->sock, &c, 1, &closed, &sent, "PT"));
		if(sent)
			return GP_NO_ERROR;
	}

	// Buffer if not sent.
	//////////////////////
	return gpiAppendCharToBuffer(connection, &peer->outputBuffer, c);
	*/
	GSI_UNUSED(c);
	GSI_UNUSED(peer);
	GSI_UNUSED(connection);
	return GP_NO_ERROR;
}
Пример #2
0
GHTTPBool ghttpPostAddFileFromMemoryW
(
	GHTTPPost post,
	const unsigned short * name,
	const char * buffer,
	int bufferLen,
	const unsigned short * reportFilename,
	const unsigned short * contentType
)
{
	char name_A[1024] = { '\0' };
	char reportFilename_A[1024] = { '\0' };
	char contentType_A[1024] = { '\0' };
	if (name != NULL)
		UCS2ToAsciiString(name, name_A);
	if (reportFilename != NULL)
		UCS2ToAsciiString(reportFilename, reportFilename_A);
	if (contentType != NULL)
		UCS2ToAsciiString(contentType, contentType_A);

	
	return ghttpPostAddFileFromMemoryA(post, name_A, buffer, bufferLen, reportFilename_A, contentType_A);
	
	GSI_UNUSED(reportFilename);
	GSI_UNUSED(contentType);
}
Пример #3
0
void gpiPeerPingReplyCallback(unsigned int ip, unsigned short port, unsigned int latency, void *userData)
{
	GSI_UNUSED(userData);
	GSI_UNUSED(latency);
	GSI_UNUSED(port);
	GSI_UNUSED(ip);
}
Пример #4
0
void gpiPeerAcceptedCallback(unsigned int ip, unsigned short port, 
							 GSUdpErrorCode error, gsi_bool rejected, void *userData)
{
	GPConnection *connection = (GPConnection *)userData;
	GPIPeer *aPeer;
	IN_ADDR anAddr;
	anAddr.s_addr = ip;
	
	aPeer = gpiGetPeerByAddr(connection, ip, port);
	if (!aPeer)
	{
		gsDebugFormat(GSIDebugCat_GP, GSIDebugType_Network, GSIDebugLevel_HotError,
			"Peer does not exist: ip-port: %s:%d\n", inet_ntoa(anAddr), port);
	}
	else
	{
		if (rejected)
		{
			aPeer->state = GPI_PEER_DISCONNECTED;
			gsDebugFormat(GSIDebugCat_GP, GSIDebugType_Network, GSIDebugLevel_Notice,
				"Peer Connection rejected: ip-port: %s:%d\n", inet_ntoa(anAddr), port);
			return;
		}
	}
	
	gsDebugFormat(GSIDebugCat_GP, GSIDebugType_Network, GSIDebugLevel_Notice,
		"Peer Connection accepted: ip-port: %s:%d\n", inet_ntoa(anAddr), port);
	
	GSI_UNUSED(userData);
	GSI_UNUSED(rejected);
	GSI_UNUSED(error);
	GSI_UNUSED(anAddr);	
}
Пример #5
0
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// This will be triggered when scCreateSession() has completed.
//    Expected to occur once per reported game session.
void createSessionCallback(SCInterfacePtr theInterface,
						   GHTTPResult theHttpResult,
                           SCResult theResult,
						   void * theUserData)
{	
	gsDebugFormat(GSIDebugCat_App, GSIDebugType_Misc, GSIDebugLevel_Notice, 
		"CreateSessionCallback: theHttpResult = %d, theResult = %s\r\n", theHttpResult, SCResultStr[theResult]);

	
	if (theHttpResult == GHTTPSuccess && theResult == SCResult_NO_ERROR)
	{
		const char * sessionId    = scGetSessionId(theInterface);
		const char * connectionId = scGetConnectionId(theInterface);

		gsDebugFormat(GSIDebugCat_App, GSIDebugType_Misc, GSIDebugLevel_Debug, "Session ID: %s\r\n", sessionId);
		gsDebugFormat(GSIDebugCat_App, GSIDebugType_Misc, GSIDebugLevel_Debug, "Connection ID: %s\r\n", connectionId);
		GSI_UNUSED(sessionId);
		GSI_UNUSED(connectionId);
	}

	gServerData.mWaitCount--; // one less request to wait for

	GSI_UNUSED(theInterface);
	GSI_UNUSED(theUserData);
}
Пример #6
0
static void EnumPlayersCallback
(
	PEER peer,
	PEERBool success,
	RoomType roomType,
	int index,
	const gsi_char * nick,
	int flags,
	void * param
)
{
	if(!success)
	{
		_tprintf(_T("Enum %s players failed\n"), RtoS[roomType]);
		return;
	}

	if(index == -1)
	{
		_tprintf(_T("--------------------\n"));
		return;
	}

	_tprintf(_T("%d: %s\n"), index, nick);
	/*if(flags & PEER_FLAG_OP)
		_tprintf(_T(" (host)\n"));
	else
		_tprintf(_T("\n"));*/
		

	GSI_UNUSED(peer);
	GSI_UNUSED(param);
	GSI_UNUSED(flags);
}
Пример #7
0
// Used to list the players in the title room.
//////////////////////////////////////////////
static void EnumTitlePlayersCallback
(
	PEER peer,
	PEERBool success,
	RoomType roomType,
	int index,
	const char * nick,
	int flags,
	void * param
)
{
	if(!success)
	{
		Wizard->MessageBox("Error listing title-room players.");
		return;
	}

	if(index == -1)
		return;

	TitlePage->UpdatePlayerPing(nick, 9999);
	GSI_UNUSED(peer);
	GSI_UNUSED(flags);
	GSI_UNUSED(roomType);
	GSI_UNUSED(param);
}
Пример #8
0
static void QRServerKeyCallback
(
	PEER peer,
	int key,
	qr2_buffer_t buffer,
	void * param
)
{
#if VERBOSE
	gsi_char verbose[256];
	_stprintf(verbose, _T("QR_SERVER_KEY | %d\n"), key);
	OutputDebugString(verbose);
#endif

	switch(key)
	{
	case HOSTNAME_KEY:
		_tprintf(_T(" Server Key callback is being called for HOSTNAME_KEY\n"));
		qr2_buffer_add(buffer, _T("My Game"));
		break;
	case NUMPLAYERS_KEY:
		_tprintf(_T(" Server Key callback is being called for NUMPLAYERS_KEY\n"));
		qr2_buffer_add_int(buffer, 1);
		break;
	case GAMEMODE_KEY:
		_tprintf(_T(" Server Key callback is being called for GAMEMODE_KEY\n"));
		qr2_buffer_add(buffer, _T("openplaying"));
		break;
	case HOSTPORT_KEY:
		_tprintf(_T(" Server Key callback is being called for HOSTPORT_KEY\n"));
		qr2_buffer_add_int(buffer, 15151);
		break;
	case MAPNAME_KEY:
		_tprintf(_T(" Server Key callback is being called for MAPNAME_KEY\n"));
		qr2_buffer_add(buffer, _T("Big Crate Room"));
		break;
	case GAMETYPE_KEY:
		_tprintf(_T(" Server Key callback is being called for GAMETYPE_KEY\n"));
		qr2_buffer_add(buffer, _T("Friendly"));
		break;
	case TIMELIMIT_KEY:
		_tprintf(_T(" Server Key callback is being called for TIMELIMIT_KEY\n"));
		qr2_buffer_add_int(buffer, 100);
		break;
	case FRAGLIMIT_KEY:
		_tprintf(_T(" Server Key callback is being called for FRAGLIMIT_KEY\n"));
		qr2_buffer_add_int(buffer, 0);
		break;
	case TEAMPLAY_KEY:
		_tprintf(_T(" Server Key callback is being called for TEAMPLAY_KEY\n"));
		qr2_buffer_add_int(buffer, 0);
		break;
	default:
		qr2_buffer_add(buffer, _T(""));
		break;
	}
	
	GSI_UNUSED(peer);
	GSI_UNUSED(param);
}
Пример #9
0
static void piPinged
(
	unsigned int IP,
	unsigned short port,
	int ping,
	const char * data,
	int len,
	PEER peer
)
{
	piPlayer * player;

	// Find the player.
	///////////////////
	player = piFindPlayerByIP(peer, IP);
	if(!player)
		return;

	// Process the ping.
	////////////////////
	piProcessPing(peer, player, ping);
	
	GSI_UNUSED(port);
	GSI_UNUSED(data);
	GSI_UNUSED(len);
}
Пример #10
0
static void JoinRoomCallback
(
 PEER peer,
 PEERBool success,
 PEERJoinResult result,
 RoomType roomType,
 void * param
 )
{
	if(!success)
	{
		_tprintf(_T("Join failure: %s"), ResultToString(result));
		return;
	}
	else
	{
		_tprintf(_T("Joined %s.\n"), RtoS[roomType]);
		/*dlg->FillPlayerList(roomType);
		if(roomType == StagingRoom)
		{
			dlg->m_name = peerGetRoomName(peer, StagingRoom);
			dlg->UpdateData(FALSE);
		}*/
	}

	GSI_UNUSED(param);
	GSI_UNUSED(roomType);
	GSI_UNUSED(peer);
}
Пример #11
0
static void piPingerReply
(
	unsigned int IP,
	unsigned short port,
	int ping,
	const char * pingData,
	int pingDataLen,
	PEER peer
)
{
	piPingerReplyData data;

	PEER_CONNECTION;

	// Find who sent the ping.
	//////////////////////////
	data.peer = peer;
	data.IP = IP;
	data.ping = ping;
	TableMap(connection->players, piPingerReplyMapFn, &data);
	
	GSI_UNUSED(port);
	GSI_UNUSED(pingData);
	GSI_UNUSED(pingDataLen);
	
}
Пример #12
0
static void NickErrorCallback
(
	PEER peer,
	int type,
	const gsi_char * badNick,
	int numSuggestedNicks,
	const gsi_char ** suggestedNicks,
	void * param
)
{
	static int errCount;

	if(errCount < 20)
	{
		_tsnprintf(nick,NICK_SIZE,_T("peerc%u"),(unsigned int)current_time());
		nick[NICK_SIZE - 1] = '\0';
		peerRetryWithNick(peer, nick);
	}
	else
	{
		//peerDisconnect(peer);
		peerRetryWithNick(peer, NULL);
	}
	errCount++;
	
	GSI_UNUSED(type);
	GSI_UNUSED(badNick);
	GSI_UNUSED(suggestedNicks);
	GSI_UNUSED(numSuggestedNicks);
	GSI_UNUSED(param);
}
Пример #13
0
static const unsigned short * piGetWatchKeyW
(
	const unsigned short * nick,
	const unsigned short * key,
	HashTable watchCache
)
{
#ifndef GSI_UNICODE
	GSI_UNUSED(nick);
	GSI_UNUSED(key);
	GSI_UNUSED(watchCache);
	return NULL; // can't use this function unless in GSI_UNICODE mode
#else
	piCacheKey keyTemp;
	piCacheKey * cacheKey;

	char* nick_A = UCS2ToUTF8StringAlloc(nick);
	char* key_A = UCS2ToUTF8StringAlloc(key);

	keyTemp.nick = (char *)nick_A;
	keyTemp.key = (char *)key_A;
	cacheKey = (piCacheKey *)TableLookup(watchCache, &keyTemp);

	gsifree(nick_A);
	gsifree(key_A);

	if (!cacheKey)
		return NULL;

	if(cacheKey->value_W)
		return cacheKey->value_W;
	return L"";
#endif
}
Пример #14
0
static GHTTPBool CompletedCallback
(
	GHTTPRequest request,
	GHTTPResult result,
	char * buffer,
	GHTTPByteCount bufferLen,
	void * param
)
{
	CGhttpmfcDlg * dlg = (CGhttpmfcDlg *)param;

	static char * resultStrings[] =
	{
		"GHTTPSuccess",
		"GHTTPOutOfMemory",
		"GHTTPBufferOverflow",
		"GHTTPParseURLFailed",
		"GHTTPHostLookupFailed",
		"GHTTPSocketFailed",
		"GHTTPConnectFailed",
		"GHTTPBadResponse",
		"GHTTPRequestRejected",
		"GHTTPUnauthorized",
		"GHTTPForbidden",
		"GHTTPFileNotFound",
		"GHTTPServerError",
		"GHTTPFileWriteFailed",
		"GHTTPFileReadFailed",
		"GHTTPFileIncomplete",
		"GHTTPFileToBig",
		"GHTTPEncryptionError",
		"GHTTPRequestCancelled"
	};

	CString msg;

	if( GHTTPSuccess == result )
	{
		msg = "File received successfully";
	}
	else
	{
		msg.Format("Error: (%d) ", result);
		if( result < 0 || result >= sizeof(resultStrings)/sizeof(resultStrings[0]) )
			msg += "Unknown - local error table may be out of date";
		else
			msg += resultStrings[(int)result];
	}

	dlg->MessageBox(msg);

	dlg->m_request = -1;

	return GHTTPTrue;

	GSI_UNUSED(bufferLen);
	GSI_UNUSED(buffer);
	GSI_UNUSED(request);
}
Пример #15
0
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Requests for communication from a peer is handled by first checking if the 
// initial message has a message handler registered for it.  Otherwise 
// the message is passed onto the app.
void gsUdpConnAttemptCB(GT2Socket socket, GT2Connection connection, unsigned int ip, 
						unsigned short port, int latency, GT2Byte * message, int len)
{
	// Get the message handler for the connection 
	int index;
	GSUdpMsgHandler aHandler;
	GSUdpRemotePeer aRemotePeer;
	GSUdpEngineObject *aUdp = gsUdpEngineGetEngine();
	char anAddr[GS_IP_ADDR_AND_PORT];
	
	gsDebugFormat(GSIDebugCat_Common, GSIDebugType_Network, GSIDebugLevel_Comment, 
		"[Udp Engine] Connection attempt from %s\n", gt2AddressToString(ip, port, anAddr));
	//If there is a handler, automatically accept a connection if the initial message is
	//the same as the handler's registered initial message
	if (len >= GS_UDP_MSG_HEADER_LEN)
	{    
		memcpy(aHandler.mInitialMsg, message, GS_UDP_MSG_HEADER_LEN);
		
		aRemotePeer.mAddr = ip;
		aRemotePeer.mPort = port;
		aRemotePeer.mConnection = connection;
		
		ArrayAppend(aUdp->mRemotePeers, &aRemotePeer);
		index = ArraySearch(aUdp->mMsgHandlers, &aHandler, gsUdpMsgHandlerCompare, 0, 0);
		if (index != NOT_FOUND)
		{
			GT2ConnectionCallbacks aCallbacks;
			
			aCallbacks.closed = gsUdpClosedRoutingCB;
			aCallbacks.connected = gsUdpConnectedRoutingCB;
			aCallbacks.ping = gsUdpPingRoutingCB;
			aCallbacks.received = gsUdpReceivedRoutingCB;

	       
			// Automatically accept connections for Message Handlers
			gt2Accept(aRemotePeer.mConnection, &aCallbacks);	
			gsDebugFormat(GSIDebugCat_Common, GSIDebugType_Network, GSIDebugLevel_Comment, 
				"[Udp Engine] Connection attempt auto-accepted for message handler\n");
			return;
		}
	}
	// all other messages go to the app
	if (aUdp->mAppConnAttempt) 
	{
		gsDebugFormat(GSIDebugCat_Common, GSIDebugType_Network, GSIDebugLevel_Comment, 
			"[Udp Engine] Connection attempt from %s, asking app to accept/reject\n", gt2AddressToString(ip, port, anAddr));
		aUdp->mAppConnAttempt(ip, port, latency, (unsigned char *)message, (unsigned int)len, aUdp->mAppUserData);
	}
	else 
	{
		// Reject any un-handled connections or unknown connections
		gt2Reject(connection, NULL, 0);
		ArrayRemoveAt(aUdp->mRemotePeers, ArrayLength(aUdp->mRemotePeers) -1);
	}
	GSI_UNUSED(socket);
	GSI_UNUSED(anAddr);
}
Пример #16
0
static GVBool gviCustomCapturePacket(GVDevice device, GVByte * packet, int * len, GVFrameStamp * frameStamp, GVScalar * volume)
{
	// not supported with custom devices
	assert(0);
	GSI_UNUSED(device);
	GSI_UNUSED(packet);
	GSI_UNUSED(len);
	GSI_UNUSED(frameStamp);
	GSI_UNUSED(volume);
	return GVFalse;
}
Пример #17
0
static void PersDataSaveCallback(int localid, int profileid, persisttype_t type, int index, int success, time_t modified, void *instance)
{
	printf("Data save callback: localid: %d profileid: %d success: %d mod: %d\n", localid, profileid, success, (int)modified);
	/*********
	instance is a pointer to the callback counter, increment it
	**********/
	(*(int *)instance)++;
	
	GSI_UNUSED(type);
	GSI_UNUSED(index);
}
Пример #18
0
static void PersDataCallback(int localid, int profileid, persisttype_t type, int index, int success, time_t modified, char *data, int len, void *instance)
{
	printf("Data get callback: localid: %d profileid: %d success: %d mod: %d len: %d data: %s\n",localid, profileid, success, (int)modified, len, data);
	/*********
	instance is a pointer to the callback counter, increment it
	**********/
	(*(int *)instance)++;
	
	GSI_UNUSED(type);
	GSI_UNUSED(index);
}
Пример #19
0
static void DisconnectedCallback
(
	PEER peer,
	const gsi_char * reason,
	void * param
)
{
	_tprintf(_T("Disconnected: %s\n"), reason);
	
	GSI_UNUSED(peer);
	GSI_UNUSED(param);
}
Пример #20
0
static void PlayerJoinedCallback
(
	PEER peer,
	RoomType roomType,
	const gsi_char * nick,
	void * param
)
{
	_tprintf(_T("%s joined the %s\n"), nick, RtoS[roomType]);
	
	GSI_UNUSED(peer);
	GSI_UNUSED(param);
}
Пример #21
0
static void PlayerChangedNickCallback
(
	PEER peer,
	RoomType roomType,
	const gsi_char * oldNick,
	const gsi_char * newNick,
	void * param
)
{
	_tprintf(_T("%s in %s changed nicks to %s\n"), oldNick, RtoS[roomType], newNick);
	
	GSI_UNUSED(peer);
	GSI_UNUSED(param);
}
Пример #22
0
static void PlayerMessageCallback
(
	PEER peer,
	const gsi_char * nick,
	const gsi_char * message,
	MessageType messageType,
	void * param
)
{
	_tprintf(_T("(PRIVATE) %s: %s\n"), nick, message);
	
	GSI_UNUSED(peer);
	GSI_UNUSED(messageType);
	GSI_UNUSED(param);
}
Пример #23
0
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// This will be triggered when scSubmitReport() has completed
//    Expected to occur once per call to scSetReportIntention
void submitReportCallback(SCInterfacePtr theInterface, 
						  GHTTPResult theHttpResult,
						  SCResult theResult,
						  void * theUserData)
{
	gsDebugFormat(GSIDebugCat_App, GSIDebugType_Misc, GSIDebugLevel_Notice, 
		"SubmitReportCallback: theHttpResult = %d, theResult = %s\r\n", theHttpResult, SCResultStr[theResult]);
	
	gServerData.mWaitCount--; // one less request to wait for

	GSI_UNUSED(theHttpResult);
	GSI_UNUSED(theResult);
	GSI_UNUSED(theInterface);
	GSI_UNUSED(theUserData);
}
Пример #24
0
static void PlayerLeftCallback
(
	PEER peer,
	RoomType roomType,
	const gsi_char * nick,
	const gsi_char * reason,
	void * param
)
{
	_tprintf(_T("%s left the %s\n"), nick, RtoS[roomType]);
	
	GSI_UNUSED(peer);
	GSI_UNUSED(param);
	GSI_UNUSED(reason);
}
Пример #25
0
// Called when the join is complete (successful or unsuccessful).
/////////////////////////////////////////////////////////////////
static void JoinGroupRoomCallback
(
	PEER peer,
	PEERBool success,
	PEERJoinResult result,
	RoomType roomType,
	void * param
)
{
	joinSuccess = success;
	GSI_UNUSED(roomType);
	GSI_UNUSED(peer);
	GSI_UNUSED(param);
	GSI_UNUSED(result);
}
Пример #26
0
static void ConnectCallback
(
	PEER peer,
	PEERBool success,
	int failureReason,
	void * param
)
{
	connectSuccess = success;
	
	GSI_UNUSED(peer);
	GSI_UNUSED(success);
	GSI_UNUSED(failureReason);
	GSI_UNUSED(param);
}
Пример #27
0
SCResult SC_CALL sciReportSetPlayerAuthInfo(SCIReport * theReport, gsi_u32 thePlayerIndex, const GSLoginCertificate * theCertificate, const gsi_u8 theAuthHash[16])
{
	SCIReportHeader * aHeader = (SCIReportHeader*)theReport->mBuffer.mData;
	gsi_u32 authDataOffset = 0;

	// Auth section is just after the roster
	authDataOffset = sizeof(SCIReportHeader) + aHeader->mRosterSectionLength;
	authDataOffset += SC_REPORT_AUTHDATA_LENGTH * thePlayerIndex;

	// copy auth data into the buffer
	// &theReport->mBuffer.mData[authDataOffset]
	GSI_UNUSED(theAuthHash);
	GSI_UNUSED(theCertificate);
	return SCResult_NO_ERROR;
}
Пример #28
0
const char *ServerBrowserErrorDescA(ServerBrowser sb, SBError error)
{
	switch (error)
	{
	case sbe_noerror:
		return "None";
		//break;
	case sbe_socketerror:
		return "Socket creation error";
		//break;
	case sbe_dnserror:
		return "DNS lookup error";
		//break;
	case sbe_connecterror:
		return "Connection failed";
		//break;
	case sbe_dataerror:
		return "Data stream error";
		//break;
	case sbe_allocerror:
		return "Memory allocation error";
		//break;
	case sbe_paramerror:
		return "Function parameter error";
		//break;
	case sbe_duplicateupdateerror:
		return "Duplicate update request error";
		//break;
	}

	GSI_UNUSED(sb);
	return "";
}
Пример #29
0
const unsigned short *ServerBrowserErrorDescW(ServerBrowser sb, SBError error)
{
	switch (error)
	{
	case sbe_noerror:
		return L"None";
		break;
	case sbe_socketerror:
		return L"Socket creation error";
		break;
	case sbe_dnserror:
		return L"DNS lookup error";
		break;
	case sbe_connecterror:
		return L"Connection failed";
		break;
	case sbe_dataerror:
		return L"Data stream error";
		break;
	case sbe_allocerror:
		return L"Memory allocation error";
		break;
	case sbe_paramerror:
		return L"Function parameter error";
		break;
	case sbe_duplicateupdateerror:
		return L"Duplicate update request error";
		break;
	}
	return L"";
	
	GSI_UNUSED(sb);
}
Пример #30
0
void CSbmfcsampleDlg::SBCallback(ServerBrowser serverBrowser, SBCallbackReason reason, SBServer server, void *instance)
{
	CString str;
	CSbmfcsampleDlg * dlg = (CSbmfcsampleDlg *)instance;

	CString address;
	if(server)
		address.Format("%s:%d", SBServerGetPublicAddress(server), SBServerGetPublicQueryPort(server));

	switch(reason)
	{
	case sbc_serveradded:
		dlg->AddServer(server, TRUE);
		break;
	case sbc_serverupdated:
		dlg->AddServer(server, TRUE);
		break;
	case sbc_serverupdatefailed:
		break;
	case sbc_serverdeleted:
		dlg->RemoveServer(server);
		break;
	case sbc_updatecomplete:
		dlg->m_progress.SetPos(100);
		break;
	case sbc_queryerror:
		str.Format("Query Error: %s\n", ServerBrowserListQueryError(dlg->m_serverBrowser));
		dlg->MessageBox(str);
		break;
	}
	
	GSI_UNUSED(serverBrowser);
}