Game Development Community

Xml-Rpc client for Torque3D

by Nathan Bowhay (ESAL) · 01/18/2010 (4:37 pm) · 1 comments

First as a note there is a bug with this that I am working on and is posted about here: www.torquepowered.com/community/forums/viewthread/109459

Also not everything the library has is implemented I basically made rappers for everything to get it to work in torque and didn't want to do that for everything.

Also the library can be found here: sourceforge.net/projects/xmlrpcpp/
But all the files you need should be in the link below.

First download this: XmlRpc in T3D.zip

Then copy the Objects folder into your projects source folder My Projects/<ProjectName>/soruce/Objects).

Next copy the xmlrpc folder into you lib directory for T3D (Engine/lib/xmlrpc). This is the same place that the zlib or the tinyxml folder can be found.

Then copy the xmlrpc.vcproj into the projects folder (My Projects/<ProjectName>/buildFiles/VisualStudio 2005/projects) and added it to your solution (open the T3D solution file for your project and drag and drop xmlrpc.vcproj from the projects folder under tinyxml in the solution explorer).

Then right click on your project dll in the solution explorer (<ProjectName> DLL) and select Project Dependencies and check xmlrpc.

Next we need to add some nice little methods that are used for error checking.

Make a new file called consoleFunctions.h and put it in the same location as the .cpp file and add it to the project in the same filter as well. In that file put:
#ifndef _CONSOLFUNCTIONS_H_
#define _CONSOLFUNCTIONS_H_

#ifndef _STRINGFUNCTIONS_H_
#include "core/strings/stringFunctions.h"
#endif

bool isValidIP(const char* ip);

bool isValidPort(U16 port);

#endif

At the end of line 9 hit enter and add:
#ifndef _CONSOLFUNCTIONS_H_
#include "console/consoleFunctions.h"
#endif

Then open up consoleFunctions.cpp:

around line 27 add:
bool isValidIP(const char* ip)
{
    unsigned b1, b2, b3, b4;
	unsigned char c;
	int rc = dSscanf(ip, "%3u.%3u.%3u.%3u%c", &b1, &b2, &b3, &b4, &c);
	if (rc != 4 && rc != 5) return false;
	if ((b1 | b2 | b3 | b4) > 255) return false;
	if (dStrspn(ip, "0123456789.") < dStrlen(ip)) return false;
	return true;
}

bool isValidPort(U16 port)
{
	return (port >= 0 && port <=65535);
}

Then around line 335 where there are some other console functions add (just so we can use them in script if we want):
ConsoleFunction(isValidPort,bool,2,2,"(string) "
                "Returns true if the string is a valid port.")
{
	TORQUE_UNUSED(argc);
	if(isInt(argv[1]))
	{
		U16 port = dAtous(argv[1]);
		return isValidPort(port);
	}
	else
		return false;
}

ConsoleFunction(isValidIP,bool,2,2,"(string) "
                "Returns true if the string is a valid ip address, excepts localhost.")
{
	TORQUE_UNUSED(argc);
	if(dStrcmp(argv[1], "localhost") == 0)
	{
		return true;
	}
	else
		return isValidIP(argv[1]);
}

Hit compile and you should be done. I didn't actually have time to go through these steps and I did them a long time ago so let me know if anything is incorrect.

Also the link for the files may change because I don't really want to use dropbox and rely on me keeping the file there. I have a post here about where I should upload: www.torquepowered.com/community/forums/viewthread/109463






#1
01/19/2010 (10:37 am)
I get the following when trying to compile this

1>Compiling...
1>consoleFunctions.cpp
1>SimXmlRpcValue.cpp
1>SimXmlRpcClient.cpp
1>..\..\..\..\..\Engine\source\console\consoleFunctions.cpp(342) : error C3861: 'isInt': identifier not found
1>..\..\..\..\..\Engine\source\console\consoleFunctions.cpp(344) : error C3861: 'dAtous': identifier not found
1>..\..\..\..\..\Engine\source\Objects\SimXmlRpcValue.cpp(334) : error C3861: 'dAtod': identifier not found
1>..\..\..\..\..\Engine\source\Objects\SimXmlRpcValue.cpp(436) : error C3861: 'dAtod': identifier not found
1>..\..\..\..\..\Engine\source\Objects\SimXmlRpcValue.cpp(440) : error C3861: 'dAtod': identifier not found
1>..\..\..\..\..\Engine\source\Objects\SimXmlRpcValue.cpp(443) : error C3861: 'dAtod': identifier not found
1>..\..\..\..\..\Engine\source\Objects\SimXmlRpcValue.cpp(513) : error C3861: 'dAtod': identifier not found
1>..\..\..\..\..\Engine\source\Objects\SimXmlRpcClient.cpp(219) : error C3861: 'dAtous': identifier not found
1>..\..\..\..\..\Engine\source\Objects\SimXmlRpcClient.cpp(292) : error C3861: 'dAtod': identifier not found