Exemple #1
0
bool Matchmaker::Init()
{
	// You can load the verifier key from the registry or from a file.  However, if you load it 
	// from the registry, please load it from your own location rather than using the default.  If you
	// get 110003 errors while authenticating, you probably aren't loading the verifier key.
#ifdef DLLSAMPLE
	if (!WONAuthLoadVerifierKeyFromFileA(FILE_VERIFIER_KEY))
#else
	if (!Identity::LoadVerifierKeyFromFile(FILE_VERIFIER_KEY))
#endif // DLLSAMPLE
	{
		OutputStringF("Failed to load verifier key from %s.", FILE_VERIFIER_KEY);
		return false;
	}
	
#ifdef DLLSAMPLE
//	WONRoutingInstallClientEnterExCallback(mRoutingServer, OnClientEnterChat, this);
	WONRoutingInstallGroupEnterExCallback(mRoutingServer, OnClientEnterChat, this);
	WONRoutingInstallGroupLeaveCallback(mRoutingServer, OnClientLeaveChat, this);
	WONRoutingInstallASCIIPeerChatCallback(mRoutingServer, OnChatReceived, this);
	WONRoutingInstallUnicodePeerChatCallback(mRoutingServer, OnChatReceived, this);
	WONRoutingInstallReconnectFailureCallback(mRoutingServer, OnReconnectFailure, this);
#else
//	mRoutingServer.InstallClientEnterExCatcherEx((void(*)(const RoutingServerClient::ClientDataWithReason&, Matchmaker*))OnClientEnterChat, this);
	mRoutingServer.InstallGroupEnterExCatcherEx((void(*)(const RoutingServerClient::GroupIdAndClientDataWithReason&, Matchmaker*))OnClientEnterChat, this);
	mRoutingServer.InstallGroupLeaveCatcherEx((void(*)(const RoutingServerClient::GroupIdAndClientIdWithReason&, Matchmaker*))OnClientLeaveChat, this);
	mRoutingServer.InstallASCIIPeerChatCatcherEx((void(*)(const RoutingServerClient::ASCIIChatMessage&, Matchmaker*))OnAsciiChatReceived, this);
	mRoutingServer.InstallUnicodePeerChatCatcherEx((void(*)(const RoutingServerClient::UnicodeChatMessage&, Matchmaker*))OnUnicodeChatReceived, this);
	mRoutingServer.InstallReconnectFailureCatcherEx((void(*)(Matchmaker* that))OnReconnectFailure, this);
#endif // DLLSAMPLE

	GetDirServers();
	GetMOTD();
	GetTitanServerList();

	if (mNumAuthServers == 0)
	{
		OutputString("No Auth Servers found in /TitanServers/Auth");
		return false;
	}

	// allow Init() to return
	OutputString("Ready");

	return true;
}
void main()
{
	WONIPAddress anAddr;
	WONError anError;

	WONInitialize();
	mEvent = CreateEvent(NULL,FALSE,FALSE,NULL);
	WONAuthLoadVerifierKeyFromRegistry("SOFTWARE\\WON\\Titan", "AuthVerifierKey");
	if(!GetCertificate("Brian123","WON","suck"))
		return;

	mSession = WONRoutingCreateSession();

	WONIPAddressSetFromString(&anAddr,"localhost:8200");
	anError = WONRoutingConnect(mSession, &anAddr, mAuth, 10000);
	printf("Connection result: %s\n",WONErrorToString(anError));
	if(anError!=WONError_Success)
		return;

	WONRoutingRegisterA(mSession,"Brian123","",FALSE,FALSE,TRUE,MyRoutingRegisterClientCallback,"RegisterA");
	WaitForSingleObject(mEvent, INFINITE);

	WONRoutingGetNumUsers(mSession,MyRoutingGetNumUsersCallback,"GetNumUsers");
	WONRoutingIsUserPresentA(mSession,"test",TRUE,TRUE,MyRoutingBoolCallback,"Good IsUserPresent");
	WONRoutingIsUserPresentA(mSession,"test2",TRUE,TRUE,MyRoutingBoolCallback,"Good IsUserPresent");
	WONRoutingGetClientList(mSession,TRUE,TRUE,TRUE,MyRoutingClientListCallback,"GetClientList");
	WONRoutingGetMembersOfGroup(mSession,4,TRUE,TRUE,TRUE,MyRoutingClientListCallback,"GetChatGroup");
	WONRoutingGetMembersOfGroup(mSession,5,TRUE,TRUE,TRUE,MyRoutingClientListCallback,"GetBadGroup");
	WONRoutingGetGroupList(mSession,MyRoutingGroupListCallback,"GetGroupList");
	WONRoutingSubscribeDataObject(mSession,2,"",0,FALSE,TRUE,MyRoutingReadDataObjectCallback,"SubscribeDataObject");
	WONRoutingBroadcastChatA(mSession,"YO YO YO!!!",FALSE);
	WONRoutingBroadcastChatAndGetResultA(mSession,"YO YO YO!!!",FALSE,MyRoutingStatusCallback, "Send Chat");


	WONRoutingInstallClientJoinAttemptCallback(mSession, MyRoutingClientNameCallback, "Join Attempt");      
	WONRoutingInstallClientEnterCallback(mSession, MyRoutingClientIdWithReasonCallback, "Client Enter");     
	WONRoutingInstallClientEnterExCallback(mSession, MyRoutingClientDataWithReasonCallback, "Client Enter Ex"); 
	WONRoutingInstallClientLeaveCallback(mSession, MyRoutingClientIdWithReasonCallback, "Client Leave");     
	WONRoutingInstallSpectatorCountCallback(mSession, MyRoutingSpectatorCallback, "Spectator Count");                       
	WONRoutingInstallGroupEnterCallback(mSession, MyRoutingGroupIdAndClientIdWithReasonCallback, "Group Enter");      
	WONRoutingInstallGroupEnterExCallback(mSession, MyRoutingGroupIdAndClientDataWithReasonCallback, "Group Enter Ex");  
	WONRoutingInstallGroupLeaveCallback(mSession, MyRoutingGroupIdAndClientIdWithReasonCallback, "Group Leave");      
	WONRoutingInstallGroupSpectatorCountCallback(mSession, MyRoutingGroupIdAndSpectatorCountCallback, "Group Spectator Count"); 
	WONRoutingInstallMuteClientCallback(mSession, MyRoutingClientIdWithFlagCallback, "Mute Client");                   
	WONRoutingInstallBecomeModeratorCallback(mSession, MyRoutingClientIdWithFlagCallback, "Become Moderator");              
	WONRoutingInstallHostChangeCallback(mSession, MyRoutingClientIdCallback, "Host Change");                                 
	WONRoutingInstallDataObjectCreationCallback(mSession, MyRoutingDataObjectWithLifespanCallback, "Data Object Creation");    
	WONRoutingInstallDataObjectDeletionCallback(mSession, MyRoutingDataObjectCallback, "Data Object Deletion");                
	WONRoutingInstallDataObjectModificationCallback(mSession, MyRoutingDataObjectModificationCallback, "Data Object Modification");
	WONRoutingInstallDataObjectReplacementCallback(mSession, MyRoutingDataObjectCallback, "Data Object Replacement");             
	WONRoutingInstallKeepAliveCallback(mSession, MyRoutingVoidCallback, "Keep Alive");                                      
	WONRoutingInstallPeerDataCallback(mSession, MyRoutingMessageWithClientIdCallback, "Peer Data");                 
	WONRoutingInstallRawPeerChatCallback(mSession, MyRoutingRawChatMessageCallback, "Raw Peer Chat");                   
	WONRoutingInstallASCIIPeerChatCallback(mSession, MyRoutingASCIIChatMessageCallback, "ASCII Peer Chat");               
	WONRoutingInstallUnicodePeerChatCallback(mSession, MyRoutingUnicodeChatMessageCallback, "Unicode Peer Chat");           
	WONRoutingInstallReconnectFailureCallback(mSession, MyRoutingVoidCallback, "Reconnect Failure");                               
	

	getch();

	WONRoutingCloseSessionHandle(mSession);
	WONAuthCloseHandle(mAuth);

	WONTerminate();
	
}