All pastes #2085504 Raw Edit

Unnamed

public text v1 · immutable
#2085504 ·published 2011-09-30 00:24 UTC
rendered paste body
  cash_array = {}


  // Update the local player's cash value.
  getDBData (false, 'corps', 'cash', 'cash_array', worldmap_loadcashdata_success(), undefined, 'name', global_corp_name)


/////
///// ... elsewhere ....
/////


// Use XMLHttpRequest to request for table data.
function getDBData (get3dmap, input_tablename, columnlist, responsedatavar, successfunc, mapoffsetlist, input_where, input_values) {

 // Add custom "where" with associated values.
 var input_values_and_where = ''
 if (input_values) input_values_and_where = '&input_where='+input_where+'&input_values='+input_values

 // Trim the column list of spaces, and don't do anything if the column list is blank!
 columnlist = columnlist.trim(); if (columnlist=='') return

 // Find out if x/y data is needed
 if (get3dmap) {var xy1='x,y,'; xy2='&orderby=x,y'} else {var xy1 = ''; xy2=''}

 // If mapoffsetlist is not defined, set it to null.
 if (typeof mapoffsetlist == 'undefined') mapoffsetlist=null

 // If mapoffsetlist is a single value, make it an array.
 if (typeof mapoffsetlist == 'number') mapoffsetlist = [mapoffsetlist]

 // Convert request into POST data.
 var requeststring = '&request_type=read&input_tablename='+input_tablename+'&columnlist='+xy1+columnlist+xy2+'&curworld_dbname='+worldmap_curworld_dbname+input_values_and_where
 // Set up the temp string and call the request function.
 var http_request  = makeRequest('dbrequest.php', requeststring, true)

 http_request.onreadystatechange = function() {
  if (http_request.readyState == 4) {
   if (http_request.status == 200) {
    if (http_request.responseText.substr(0,5) == 'Error') {alert(http_request.responseText); return}
    // Populate responsedatavar with the data.
    var tempdata = http_request.responseText
    var splitarray = new Array()
    var xcoords = new Array(); var ycoords = new Array(); var onedarray=true, x=0, y=0
    var header_version = tempdata.charCodeAt(0)
    if (header_version != 0) {alert('Unable to cope with this response text header version. ('+header_version+')'); return}
    var column_amount = tempdata.charCodeAt(1)
    var c = 0, c2 = 0, len = column_amount*9+2
    if (window[responsedatavar]==null) window[responsedatavar] = new Array()
    for (i=2; i<len; i+=9) {
     var cursubarray_bytesize    = (tempdata.charCodeAt(i)&0xff)+1
     var cursubarray_indexlength = ((tempdata.charCodeAt(i+1)&0xff)<<8)+(tempdata.charCodeAt(i+2)&0xff)
     var cursubarray_startread   = ((tempdata.charCodeAt(i+3)&0xff)<<16)+((tempdata.charCodeAt(i+4)&0xff)<<8)+(tempdata.charCodeAt(i+5)&0xff)
     var cursubarray_endread     = ((tempdata.charCodeAt(i+6)&0xff)<<16)+((tempdata.charCodeAt(i+7)&0xff)<<8)+(tempdata.charCodeAt(i+8)&0xff)
     if (get3dmap === true) {if ((c==2) && (onedarray===true)) {c=0; onedarray = false}}
     // Now load in the data to the target array.
     if ((onedarray === true) && (get3dmap === true)) {
      if (c==0) {targetarray = xcoords} else {targetarray = ycoords}
     } else {
      if (mapoffsetlist===null) {
       if (typeof window[responsedatavar][c]=='undefined') window[responsedatavar][c]=new Array()
       targetarray = window[responsedatavar][c]
      } else {
       if (typeof window[responsedatavar][mapoffsetlist[c]]=='undefined') window[responsedatavar][mapoffsetlist[c]]=new Array()
       targetarray = window[responsedatavar][mapoffsetlist[c]]
      }
     }

     var k=0; var j=0
     if (onedarray === true) {
     switch (cursubarray_bytesize) {
     case 21:
      var endread1 = cursubarray_startread+cursubarray_indexlength
      for (j=cursubarray_startread; j<endread1; j++) {
       splitarray[k] = tempdata.charCodeAt(j)&0xff; k++
      }
      k=0; var curpointer = endread1
      for (j=0; j<cursubarray_indexlength; j++) {
       targetarray[k] = tempdata.substr(curpointer, splitarray[j])
       k++; curpointer += splitarray[j]
      }
     break  
     case 1: // Byte ("tinyint")
      for (j=cursubarray_startread; j<cursubarray_endread; j++) {
       targetarray[k] = tempdata.charCodeAt(j)&0xff; k++
      }
     break
     case 2: // Double-byte ("smallint")
      for (j=cursubarray_startread; j<cursubarray_endread; j+=2) {
       targetarray[k] = ((tempdata.charCodeAt(j)&0xff)<<8)+tempdata.charCodeAt(j+1)&0xff; k++
      }
     break
     case 3: // Three bytes ("mediumint")
      for (j=cursubarray_startread; j<cursubarray_endread; j+=3) {
       targetarray[k] = ((tempdata.charCodeAt(j)&0xff)<<16)+((tempdata.charCodeAt(j+1)&0xff)<<8)+tempdata.charCodeAt(j+2)&0xff; k++
      }
     break
     case 4: // Integer ("int")
      for (j=cursubarray_startread; j<cursubarray_endread; j+=4) {
       targetarray[k] = ((tempdata.charCodeAt(j)&0xff)<<24)+((tempdata.charCodeAt(j+1)&0xff)<<16)+((tempdata.charCodeAt(j+2)&0xff)<<8)+tempdata.charCodeAt(j+3)&0xff; k++
      }
     break
     }
     } else {
     switch (cursubarray_bytesize) {
     case 21:
      var endread1 = cursubarray_startread+cursubarray_indexlength
      for (j=cursubarray_startread; j<endread1; j++) {
       splitarray[k] = tempdata.charCodeAt(j)&0xff; k++
      }
      k=0; var curpointer = endread1
      for (j=0; j<cursubarray_indexlength; j++) {
       x = xcoords[k]; y = ycoords[k]
       if (typeof targetarray[x] == "undefined") targetarray[x] = new Array()
       targetarray[x][y] = tempdata.substr(curpointer, splitarray[j])
       k++; curpointer += splitarray[j]
      }
     break  
     case 1: // Byte ("tinyint")
      for (j=cursubarray_startread; j<cursubarray_endread; j++) {
       x = xcoords[k]; y = ycoords[k]
       if (typeof targetarray[x] == "undefined") targetarray[x] = new Array()
       targetarray[x][y] = tempdata.charCodeAt(j)&0xff; k++
      }
     break
     case 2: // Double-byte ("smallint")
      for (j=cursubarray_startread; j<cursubarray_endread; j+=2) {
       x = xcoords[k]; y = ycoords[k]
       if (typeof targetarray[x] == "undefined") targetarray[x] = new Array()
       targetarray[x][y] = ((tempdata.charCodeAt(j)&0xff)<<8)+tempdata.charCodeAt(j+1)&0xff; k++
      }
     break

     case 3: // Three bytes ("mediumint")
      for (j=cursubarray_startread; j<cursubarray_endread; j+=3) {
       x = xcoords[k]; y = ycoords[k]
       if (typeof targetarray[x] == "undefined") targetarray[x] = new Array()
       targetarray[x][y] = ((tempdata.charCodeAt(j)&0xff)<<16)+((tempdata.charCodeAt(j+1)&0xff)<<8)+tempdata.charCodeAt(j+2)&0xff; k++
      }
     break
     case 4: // Integer ("int")
      for (j=cursubarray_startread; j<cursubarray_endread; j+=4) {
       x = xcoords[k]; y = ycoords[k]
       if (typeof targetarray[x] == "undefined") targetarray[x] = new Array()
       targetarray[x][y] = ((tempdata.charCodeAt(j)&0xff)<<24)+((tempdata.charCodeAt(j+1)&0xff)<<16)+((tempdata.charCodeAt(j+2)&0xff)<<8)+tempdata.charCodeAt(j+3)&0xff; k++
      }
     break
     }
     }
     c++
    }
    if (typeof successfunc=='string') {
alert(successfunc)
eval(successfunc)} else {
alert('test2')
//successfunc(window[responsedatavar])
}
   } else {
    alert('There was a problem with a database request. Please try again.')
   }
  }
 }
}