JimHawkins, I'd be able to do the same 'code once', port many as Tier 1 and Tier 2?
If so, I just might need to dust off my Pascal skills (it's been a long time).
MarcoBruti, I have no intention about working in ObjectiveC for now.
I've had it explained that the same C++ files that I build in Visual Studio, will also build in Xcode and the Android environment. So, no Java or Objective C needed (for AppGameKit anyway).
But you are right about having the Tier 1 functions work.
My issue with the HTTP ones doing encoding is one I thought of because I do a lot of web work (after 20 years in the satellite business, sigh....).
As the current HTTP commands are, it would be very hard to build the code that supports them to properly encode the data passed. It is hard to tell whether an equal sign is meant to be for new data or is part of the data. I put together the following set of code to allow 'fixing' the way I want it. (Not elegant, but it works.)
global g_http AS integer
global g_dom AS string
global g_httpargs AS string
g_httpargs = ""
function makeConnection(dom AS string)
// assume not good
i_ret = 1
g_http = 0
// create the initial connection
g_http = CreateHTTPConnection()
// check for ok
if g_http > 0
// store the domain
g_dom = dom
// connect to the host
i_ret = SetHTTPHost(g_http, g_dom, 0)
// check the setting
if i_ret < 1
// some sort of problem
showErrorMessage(0.5,0.5,"Unable to connect to "+g_dom)
i_ret = 1
else
// make sure good
i_ret = 0
endif
else
showErrorMessage(0.5,0.5,"Unable to make HTTP connection")
endif
// return status
endfunction i_ret
function createHTTPargValuePair(varname AS string,string_to_encode AS string)
// initialise the strings
// start the output string with the variable name and an equals sign
string_output AS string = varname + Chr(61)
char_str AS string = ""
hex_code AS string = ""
// get the length of the string
enc_len = len(string_to_encode)
// get the length of the string to encode
FOR i_ch = 1 TO enc_len
// grab the character
char_str = Mid(string_to_encode,i_ch,1)
ascii_code = Asc(char_str)
// check for values we want to encode
IF (ascii_code =< 47) OR (ascii_code => 123) OR (ascii_code => 58 AND ascii_code =< 64) OR (ascii_code => 91 AND ascii_code =< 96)
// convert to hex
hex_code = Hex(ascii_code)
// make sure it is two characters long
IF Len(hex_code) < 2 THEN hex_code = "0" + hex_code
// add hex encoding to output string
string_output = string_output + "%" + hex_code
ELSE
// simply add the character
string_output = string_output + char_str
ENDIF
next i_ch
endfunction string_output
function startHTTPargSet(varname AS string,varvalue AS string)
// store the first set
g_httpargs = createHTTPargValuePair(varname,varvalue)
endfunction
function addHTTPargSet(varname AS string,varvalue AS string)
// store the first set
g_httpargs = g_httpargs + createHTTPargValuePair("&"+varname,varvalue)
endfunction
function getHTTPargSet()
// simply return what was created
endfunction g_httpargs
function processHTTPpageWithData(page AS string,data_in AS string)
// assume a timeout problem
http$ = "99|0"
// we want to catch a timeout
max_time = Timer() + 60
// start the command
i_async = SendHTTPRequestASync(g_http, page, data_in)
// wait for a response
while (GetHTTPResponseReady(g_http) = 0) AND (Timer() < max_time)
sync()
endwhile
// did we get something
if Timer() <= max_time
// get the response
http$ = GetHTTPResponse(g_http)
endif
endfunction http$
Usage example:
// build the arguments
startHTTPargSet("tg_id",str(TRIASSIC_GAME_ID))
addHTTPargSet("tg_name",g_player.user_name)
addHTTPargSet("is_same",str(is_same))
// send the name registration request
http$ = processHTTPpageWithData("tgc/add_player.php",getHTTPargSet())
Cheers,
Ancient Lady