package com.lloydm.geosword.common;

import java.io.File;
import java.io.IOException;
import java.util.Random;

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;

import android.app.Service;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.net.Uri;
import android.os.IBinder;
import android.util.Log;

@SuppressWarnings("deprecation")
public class UploadService extends Service
{
     private final static String TAG = "com.lloydm.geosword.common.UploadService";

     private SharedPreferences prefs = null;
     private SharedPreferences.Editor prefsedit = null;

     public final static boolean TESTBATTLES = false;// false; //yep while
                                                                                                                                                                                                     // balancing the fleets...

     public static int TESTBATTLEMASK = 15; // type of ships allowed...

     private final static String URL_ALIVE = "http://mattiesgames.com/convergence/game_php_pg_server2/pg_alive.php";

     private final static String URL_NEWGAME = Config.WEBPATH + "?data=1&"; // I
                                                                                                                                                                                                                                                                                                 // think
                                                                                                                                                                                                                                                                                                 // exp
                                                                                                                                                                                                                                                                                                 // could
                                                                                                                                                                                                                                                                                                 // need
                                                                                                                                                                                                                                                                                                 // tweaking....
     private final static String URL_JOINGAME = Config.WEBPATH + "?data=2&"; // php
                                                                                                                                                                                                                                                                                                     // code
                                                                                                                                                                                                                                                                                                     // works
                                                                                                                                                                                                                                                                                                     // fine
                                                                                                                                                                                                                                                                                                     // for
                                                                                                                                                                                                                                                                                                     // this
                                                                                                                                                                                                                                                                                                     // too...
     private final static String URL_ENTERGAME = Config.WEBPATH + "?data=4&"; // php
                                                                                                                                                                                                                                                                                                         // code
                                                                                                                                                                                                                                                                                                         // seems
                                                                                                                                                                                                                                                                                                         // ok...
     public final static String URL_TESTLOGIN = Config.WEBPATH + "?data=5&"; // php
                                                                                                                                                                                                                                                                                                     // code
                                                                                                                                                                                                                                                                                                     // works
                                                                                                                                                                                                                                                                                                     // fine
                                                                                                                                                                                                                                                                                                     // for
                                                                                                                                                                                                                                                                                                     // this.

     private final static String URL_REGISTER = Config.WEBPATH + "?data=6&"; // php
                                                                                                                                                                                                                                                                                                     // code
                                                                                                                                                                                                                                                                                                     // works
                                                                                                                                                                                                                                                                                                     // fine
                                                                                                                                                                                                                                                                                                     // for
                                                                                                                                                                                                                                                                                                     // this...

     private final static String URL_GETMYONLINEGAMES = Config.WEBPATH + "?data=7&";
     private final static String URL_GETSTARMAP = Config.WEBPATH + "?data=8&";
     private final static String URL_GETBATTLEDOWNLOADLINKS = Config.WEBPATH + "?data=47&";

     private final static String URL_LAUNCHATTACK = Config.WEBPATH + "?data=9&";

     private final static String URL_GETWORLDCAMPAIGN = Config.WEBPATH + "?data=88";
     // private final static String URL_LAUNCHWORLDATTACK = Config.WEBPATH + "?data=89&tid=";
     // private final static String URL_UPLOADWCBATTLERESULT = Config.WEBPATH + "?data=87&";

     private final static String URL_GETAISLIDERVALUES = Config.WEBPATH + "?data=12&";
     private final static String URL_GETPOTENTIALFLEETSTOATTACK = Config.WEBPATH + "?data=13&";
     private final static String URL_GETFLEETINFO = Config.WEBPATH + "?data=14&";

     private final static String URL_GETSHIPARMAMENTS = Config.WEBPATH + "?data=18&";
     private final static String URL_GETSHIPINFO = Config.WEBPATH + "?data=19&";

     private final static String URL_SETAISLIDERVALUE = Config.WEBPATH + "?data=22&";

     // good old look 44......
     private final static String URL_UPLOADBATTLERESULT = Config.WEBPATH + "?data=44&";
     // and 45
     private final static String URL_GETRESEARCHINFO2 = Config.WEBPATH + "?data=45&";
     // and 46
     private final static String URL_UPDATERESEARCH2 = Config.WEBPATH + "?data=46&";

     // and 52 29-jun-2015 callsigns....
     private final static String URL_GETTEAMS = Config.WEBPATH + "?data=52&";

     public final static int LOGIN_WEB_ERROR = 1;
     public final static int LOGIN_NOT_FOUND = 2;

     public final static int REGISTER_INVALID_USER = 3;
     public final static int REGISTER_BAD_CREDENTIALS = 4;
     public final static int REGISTER_WEB_ERROR = 1;

     public final static int JOINERROR_GAMEFULL = 5;
     public final static int JOINERROR_BADPASS = 6;
     public final static int JOINERROR_GAMEOVER = 7;

     public final static int CREATEERROR_TOOMANY = 8;

     public final static int NETWORK_GENERALERROR = 10;

     public final static int JOINERROR_CONTINUE = 11;

     private String username = "";
     private String userpass = "";

     private String encodedusername = "";
     private String encodeduserpass = "";

     private volatile boolean weberror = false;
     private volatile boolean loginsuccess = false;

     @Override
     public void onCreate()
     {

     }

     @Override
     public IBinder onBind(Intent intent)
     {

                     return null;
     }

     private void encodeuserdetails()
     {
                     encodedusername = Uri.encode(username);
                     // technically we should encrypt the password before sending....probably
                     // do it here....
                     encodeduserpass = Uri.encode(encryptpassword(userpass));
                     Log.d(TAG, "Encode User Details:" + encodedusername + " " + encodeduserpass);
     }

     private String encryptpassword(String pass)
     {
                     return pass;
     }

     private void getuser()
     {
                     SharedPreferences sp = getSharedPreferences("com.lloydm.geosword", MODE_PRIVATE);
                     username = sp.getString("com.lloydm.geosword.username", "");
                     userpass = sp.getString("com.lloydm.geosword.userpass", "");
                     Log.d(TAG, "getuser() Username:" + username + " Pass:" + userpass);
                     encodeuserdetails();
                     testlogin();

     }

     private void setuser(String newusername, String newuserpass)
     {
                     SharedPreferences sp = getSharedPreferences("com.lloydm.geosword", MODE_PRIVATE);
                     Editor edit = sp.edit();
                     edit.putString("com.lloydm.geosword.username", newusername);
                     edit.putString("com.lloydm.geosword.userpass", newuserpass);
                     edit.commit();
                     Log.d(TAG, "Set User:" + newusername + " " + newuserpass);
     }

     private void setuser(String newusername, String newuserpass, String newcallsign)
     {
                     SharedPreferences sp = getSharedPreferences("com.lloydm.geosword", MODE_PRIVATE);
                     Editor edit = sp.edit();
                     edit.putString("com.lloydm.geosword.username", newusername);
                     edit.putString("com.lloydm.geosword.userpass", newuserpass);
                     edit.putString("com.lloydm.geosword.callsign", newcallsign);
                     edit.commit();
                     Log.d(TAG, "Set User:" + newusername + " " + newuserpass + " " + newcallsign);
     }

     private void testlogin()
     {
                     String url = URL_TESTLOGIN + "encodedusername=" + encodedusername + "&encodeduserpass=" + encodeduserpass;
                     String result = HTTPGet.GetURL(url);
                     Log.d(TAG, "testlogin() - result:" + result);
                     weberror = false;
                     if (result.equals("success"))
                     {
                                     // all good....
                                     loginsuccess = true;
                                     return;
                     }
                     if (result.equals("fail"))
                     {
                                     // most likely no account under those credentials..
                                     username = "";
                                     userpass = "";
                                     encodeuserdetails();
                                     loginsuccess = false;
                                     return;
                     }
                     // any other result indicates there was possibly an error....in which
                     // case set the username etc to "" but
                     // indicate that there was a web error most likely....
                     loginsuccess = false;
                     weberror = true;
     }

     /*
         * private String[] getgamelistfromresult(String result) { Log.d(TAG, "getgamelistfromresult() result:" + result); String[] output = null; output = result.split(":"); return output; }
         *
/
     private boolean notloggedin()
     {
                     if (username.equals("") && userpass.equals(""))
                     {
                                     Log.d(TAG, "notloggedin() - true, not logged in");
                                     return true;
                     }
                     if (!loginsuccess)
                     {
                                     Log.d(TAG, "notloggedin() - true, not logged in");
                                     return true;
                     }
                     Log.d(TAG, "notloggedin() - false - user is logged in");
                     return false;
     }

     private boolean validuserinfo(String name, String pass, String screenname)
     {
                     if (name.equals(""))
                     {
                                     Log.d(TAG, "validuserinfo() name blank");
                                     return false;
                     }
                     if (pass.equals(""))
                     {
                                     Log.d(TAG, "validuserinfo() pass blank");
                                     return false;
                     }
                     if (screenname.equals(""))
                     {
                                     Log.d(TAG, "validuserinfo() screenname blank");
                                     return false;
                     }
                     // other validations can come later....
                     Log.d(TAG, "validuserinfo() all good");
                     return true;

     }

     @Override
     public int onStartCommand(Intent intent, int flags, int startId)
     {
                     // technically there is a bit of extra information that we need here....
                     // since mac address is not what we want to use to identify the player -
                     // the player needs
                     // an actual account....a unique actual account...
                     // and a password....
                     // there's no two ways about it...
                     // I will have to include a login eventually......(easy enough to do)

                     String action = intent.getAction();
                     Log.d(TAG, "onStartCommand() action = " + action);


                     final long uid = intent.getLongExtra("com.lloydm.geosword.common.UploadService.uniqueid", -1);

                     if (action.equals("com.lloydm.geosword.common.UploadService.isserveralive"))
                     {
                                     final int servid = startId;
                                     new Thread(new Runnable()
                                     {
                                                     @Override
                                                     public void
run()
                                                     {
                                                                     String result = HTTPGet.GetURL(URL_ALIVE);
                                                                     if (result == null)
                                                                     {
                                                                                     result = "";
                                                                     }
                                                                     if (!result.equals("ALIVE"))
                                                                     {
                                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.MainMenuActivity.serverdead");
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.MainMenuActivity.serverdeadresult", true);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                     sendBroadcast(broadcastintent);
                                                                                     stopSelf(servid);
                                                                                     return;
                                                                     }
                                                                     stopSelf(servid);
                                                     }

                                     }).start();
                     }

                     if (action.equals("com.lloydm.geosword.common.UploadService.newuser"))
                     {
                                     // try and register account with these credentials.....
                                     final String newusername = intent.getStringExtra("com.lloydm.geosword.activities.AuthenticateActivity.newusername");
                                     final String newuserpass = intent.getStringExtra("com.lloydm.geosword.activities.AuthenticateActivity.newuserpass");
                                     final String newscreenname = intent.getStringExtra("com.lloydm.geosword.activities.AuthenticateActivity.newscreenname");

                                     final int servid = startId;

                                     if (validuserinfo(newusername, newuserpass, newscreenname))
                                     {
                                                     new Thread(new Runnable()
                                                     {

                                                                     @Override
                                                                     public void
run()
                                                                     {

                                                                                     String encodednewusername = Uri.encode(newusername);
                                                                                     String encodednewuserpass = Uri.encode(newuserpass);
                                                                                     String encodednewscreenname = Uri.encode(newscreenname);
                                                                                     String url = URL_REGISTER + "encodedusername=" + encodednewusername + "&encodeduserpass=" + encodednewuserpass + "&encodedscreenname=" + encodednewscreenname;
                                                                                     String result = HTTPGet.GetURL(url);
                                                                                     Log.d(TAG, "new user - result:" + result);
                                                                                     if (result == null)
                                                                                     {
                                                                                                     result = "";
                                                                                     }
                                                                                     if (result.equals("true"))
                                                                                     {
                                                                                                     // yep all good - registered...so we will set our
                                                                                                     // new login details....
                                                                                                     setuser(newusername, newuserpass, newscreenname);
                                                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.AuthenticateActivity.newuser");
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.AuthenticateActivity.resultcode", true);
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                                     sendBroadcast(broadcastintent);
                                                                                                     stopSelf(servid);

                                                                                                     return;
                                                                                     }
                                                                                     if (result.equals("false"))
                                                                                     {
                                                                                                     // most likely account already exists......
                                                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.AuthenticateActivity.newuser");
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.AuthenticateActivity.resultcode", false);
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.AuthenticateActivity.reason", REGISTER_INVALID_USER);
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                                     sendBroadcast(broadcastintent);
                                                                                                     stopSelf(servid);
                                                                                                     return;
                                                                                     }
                                                                                     // any other reason is a fail probably due to a
                                                                                     // connection error....
                                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.AuthenticateActivity.newuser");
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.AuthenticateActivity.resultcode", false);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.AuthenticateActivity.reason", REGISTER_WEB_ERROR);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                     sendBroadcast(broadcastintent);
                                                                                     stopSelf(servid);

                                                                     }
                                                     }).start();

                                     }
                                     else
                                     {
                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.AuthenticateActivity.newuser");
                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.AuthenticateActivity.resultcode", false);
                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.AuthenticateActivity.reason", REGISTER_BAD_CREDENTIALS);
                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                     sendBroadcast(broadcastintent);
                                                     stopSelf(servid);
                                     }

                     }
                     if (action.equals("com.lloydm.geosword.common.UploadService.login"))
                     {
                                     // set username etc and try and login....returning success etc...
                                     final String newusername = intent.getStringExtra("com.lloydm.geosword.activities.AuthenticateActivity.username");
                                     final String newuserpass = intent.getStringExtra("com.lloydm.geosword.activities.AuthenticateActivity.userpass");
                                     final int servid = startId;
                                     if (validuserinfo(newusername, newuserpass, "null"))
                                     {
                                                     new Thread(new Runnable()
                                                     {

                                                                     @Override
                                                                     public void
run()
                                                                     {
                                                                                     setuser(newusername, newuserpass);
                                                                                     getuser();
                                                                                     if (loginsuccess)
                                                                                     {
                                                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.AuthenticateActivity.login");
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.AuthenticateActivity.resultcode", true);
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                                     sendBroadcast(broadcastintent);
                                                                                                     stopSelf(servid);

                                                                                     }
                                                                                     else
                                                                                     {
                                                                                                     if (weberror)
                                                                                                     {
                                                                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.AuthenticateActivity.login");
                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.AuthenticateActivity.resultcode", false);
                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.AuthenticateActivity.reason", LOGIN_WEB_ERROR);
                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                                                     sendBroadcast(broadcastintent);
                                                                                                                     stopSelf(servid);

                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.AuthenticateActivity.login");
                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.AuthenticateActivity.resultcode", false);
                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.AuthenticateActivity.reason", LOGIN_NOT_FOUND);
                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                                                     sendBroadcast(broadcastintent);
                                                                                                                     stopSelf(servid);

                                                                                                     }
                                                                                     }

                                                                     }
                                                     }).start();
                                     }

                     }
                     if (action.equals("com.lloydm.geosword.common.UploadService.logout"))
                     {
                                     // very easy...no database connection needed at all......
                                     setuser("", "");
                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.AuthenticateActivity.logout");
                                     broadcastintent.putExtra("com.lloydm.geosword.activities.AuthenticateActivity.resultcode", true);
                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                     sendBroadcast(broadcastintent);
                                     final int servid = startId;
                                     stopSelf(servid);
                     }

                     if (action.equals("com.lloydm.geosword.common.UploadService.enterthewarzone"))
                     {
                                     // get the game id from it....
                                     // and the team id from it....

                                     final int gameid = intent.getIntExtra("com.lloydm.geosword.common.UploadService.enterthewarzone.gameid", -1);
                                     final int teamid = intent.getIntExtra("com.lloydm.geosword.common.UploadService.enterthewarzone.teamid", 0);
                                     final int servid = startId;
                                     if (gameid == -1 || teamid == 0)
                                     {
                                                     // return a fail result
                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.PreGameLobbyActivity.entergame");
                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.PreGameLobbyActivity.resultcode", false);
                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                     sendBroadcast(broadcastintent);
                                                     stopSelf(servid);
                                     }
                                     else
                                     {
                                                     // tell the database we're coming in....Ooh he's coming in...I
                                                     // feel safer already!
                                                     new Thread(new Runnable()
                                                     {

                                                                     @Override
                                                                     public void
run()
                                                                     {

                                                                                     getuser();

                                                                                     if (notloggedin())
                                                                                     {
                                                                                                     // return a fail result
                                                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.PreGameLobbyActivity.entergame");
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.PreGameLobbyActivity.resultcode", false);
                                                                                                     if (weberror)
                                                                                                     {
                                                                                                                     // most likely a connection failure of some
                                                                                                                     // sort...
                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.PreGameLobbyActivity.authenticationerror", LOGIN_WEB_ERROR);
                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     // appears that the user may not actually have a
                                                                                                                     // login....or at least those credentials are
                                                                                                                     // wrong....
                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.PreGameLobbyActivity.authenticationerror", LOGIN_NOT_FOUND);
                                                                                                     }
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                                     sendBroadcast(broadcastintent);
                                                                                                     stopSelf(servid);
                                                                                                     return;
                                                                                     }

                                                                                     String url = URL_ENTERGAME + "encodedusername=" + encodedusername + "&encodeduserpass=" + encodeduserpass;
                                                                                     url += "&gameid=" + gameid + "&teamid=" + teamid;
                                                                                     String result = HTTPGet.GetURL(url);
                                                                                     Log.d(TAG, "enter game - result:" + result);
                                                                                     if (result == null)
                                                                                     {
                                                                                                     result = "";
                                                                                     }
                                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.PreGameLobbyActivity.entergame");
                                                                                     if (result.indexOf("true") != 0)
                                                                                     {
                                                                                                     if (result.startsWith("X"))
                                                                                                     {
                                                                                                                     Log.i(TAG, "team taken already");
                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.PreGameLobbyActivity.resultcode", true);
                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.PreGameLobbyActivity.teamid", -1);
                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.PreGameLobbyActivity.playerid", -1);
                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.PreGameLobbyActivity.teams", result.substring(1, 6));
                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.PreGameLobbyActivity.resultcode", false);
                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.PreGameLobbyActivity.teamid", -1);
                                                                                                                     if (result.equals("full"))
                                                                                                                     {
                                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.PreGameLobbyActivity.failurereasoncode", JOINERROR_GAMEFULL);
                                                                                                                     }
                                                                                                                     if (result.equals("ende"))
                                                                                                                     {
                                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.PreGameLobbyActivity.failurereasoncode", JOINERROR_GAMEOVER);
                                                                                                                     }
                                                                                                     }
                                                                                     }
                                                                                     else
                                                                                     {
                                                                                                     int playerid = -1;
                                                                                                     try
                                                                                                     {
                                                                                                                     playerid = Integer.decode(result.substring(4));
                                                                                                     }
                                                                                                     catch (Exception e)
                                                                                                     {

                                                                                                     }
                                                                                                     Log.d(TAG, "PlayerID:" + playerid);
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.PreGameLobbyActivity.resultcode", true);
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.PreGameLobbyActivity.teamid", teamid);
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.PreGameLobbyActivity.playerid", playerid);

                                                                                     }
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                     sendBroadcast(broadcastintent);
                                                                                     stopSelf(servid);

                                                                     }
                                                     }).start();
                                     }
                     }

                     /*
                         * if (action.equals("com.lloydm.geosword.common.UploadService.listgame")) { new Thread(new Runnable() {
                         *
                         * @Override public void run() { getuser(); if (notloggedin()) { // return a fail result Intent broadcastintent = new Intent("com.lloydm.geosword.activities.JoinOnlineGameActivity.listgame");
                         * broadcastintent.putExtra("com.lloydm.geosword.activities.JoinOnlineGameActivity.resultcode", false); if (weberror) { // most likely a connection failure of some sort...
                         * broadcastintent.putExtra("com.lloydm.geosword.activities.JoinOnlineGameActivity.authenticationerror", LOGIN_WEB_ERROR); } else { // appears that the user may not actually have a //
                         * login....or at least those credentials are // wrong.... broadcastintent.putExtra("com.lloydm.geosword.activities.JoinOnlineGameActivity.authenticationerror", LOGIN_NOT_FOUND); }
                         * broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid); sendBroadcast(broadcastintent);
                         *
                         * return; }
                         *
                         * String url = URL_LISTGAME + "encodedusername=" + encodedusername + "&encodeduserpass=" + encodeduserpass; String result = HTTPGet.GetURL(url); Log.d(TAG, "list game - result:" + result); if
                         * (result == null) { result = ""; } Intent broadcastintent = new Intent("com.lloydm.geosword.activities.JoinOnlineGameActivity.listgame"); if (result.equals("fail") || result.equals("")) {
                         * broadcastintent.putExtra("com.lloydm.geosword.activities.JoinOnlineGameActivity.resultcode", false); } else {
                         * broadcastintent.putExtra("com.lloydm.geosword.activities.JoinOnlineGameActivity.resultcode", true); String[] data = getgamelistfromresult(result);
                         * broadcastintent.putExtra("com.lloydm.geosword.activities.JoinOnlineGameActivity.data", data); } broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                         * sendBroadcast(broadcastintent); } })
.start(); }
                         *
/
                     if (action.equals("com.lloydm.geosword.common.UploadService.joingame"))
                     {
                                     String gamename = intent.getStringExtra("com.lloydm.geosword.common.UploadService.gamename");
                                     String password = intent.getStringExtra("com.lloydm.geosword.common.UploadService.gamepassword");
                                     final int servid = startId;
                                     if (password == null)
                                     {
                                                     password = "";
                                     }
                                     if (gamename == null)
                                     {
                                                     gamename = "";
                                     }

                                     if (!gamename.equals("") && !password.equals(""))
                                     {
                                                     // we've clicked join.......
                                                     final String pass = password;
                                                     final String gname = gamename;
                                                     new Thread(new Runnable()
                                                     {

                                                                     @Override
                                                                     public void
run()
                                                                     {
                                                                                     getuser();
                                                                                     if (notloggedin())
                                                                                     {
                                                                                                     // return a fail result
                                                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.JoinOnlineGameActivity.joingame");
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.JoinOnlineGameActivity.resultcode", false);
                                                                                                     if (weberror)
                                                                                                     {
                                                                                                                     // most likely a connection failure of some
                                                                                                                     // sort...
                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.JoinOnlineGameActivity.failurereasoncode", LOGIN_WEB_ERROR);
                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.JoinOnlineGameActivity.authenticationerror", LOGIN_WEB_ERROR);
                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     // appears that the user may not actually have a
                                                                                                                     // login....or at least those credentials are
                                                                                                                     // wrong....
                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.JoinOnlineGameActivity.failurereasoncode", LOGIN_NOT_FOUND);
                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.JoinOnlineGameActivity.authenticationerror", LOGIN_NOT_FOUND);
                                                                                                     }
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                                     sendBroadcast(broadcastintent);
                                                                                                     stopSelf(servid);
                                                                                                     return;
                                                                                     }
                                                                                     String url = URL_JOINGAME + "gamename=" + Uri.encode(gname) + "&encodedusername=" + encodedusername + "&encodeduserpass=" + encodeduserpass;
                                                                                     if (!pass.equals(""))
                                                                                     {
                                                                                                     url = url + "&gamepassword=" + Uri.encode(pass);
                                                                                     }
                                                                                     String result = HTTPGet.GetURL(url);
                                                                                     Log.d(TAG, "join game - result:" + result);
                                                                                     // check result......
                                                                                     String[] teaminfo = null;

                                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.JoinOnlineGameActivity.joingame");
                                                                                     if (result.indexOf("true") == 0)
                                                                                     {
                                                                                                     String resultdata = result.substring(4);
                                                                                                     teaminfo = resultdata.split(":");
                                                                                                     // actually 9 elements....
                                                                                                     // element 8 = gameid, and the 8th element is
                                                                                                     // ignored on returning....
                                                                                                     int gid = Integer.decode(teaminfo[8]);

                                                                                                     // should be 8 elements regardless....of how many
                                                                                                     // teams there actually are.....teams not required
                                                                                                     // will come back with all -1 values....
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.JoinOnlineGameActivity.resultcode", true);
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.JoinOnlineGameActivity.gameid", gid);
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.JoinOnlineGameActivity.teaminfo", teaminfo);
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                                     sendBroadcast(broadcastintent);
                                                                                                     stopSelf(servid);
                                                                                     }
                                                                                     else
                                                                                     {
                                                                                                     if (result.indexOf("full") == 0)
                                                                                                     {

                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.JoinOnlineGameActivity.resultcode", false);
                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.JoinOnlineGameActivity.gameid", -1);
                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.JoinOnlineGameActivity.failurereasoncode", JOINERROR_GAMEFULL);
                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                                                     sendBroadcast(broadcastintent);
                                                                                                                     stopSelf(servid);
                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     if (result.indexOf("badp") == 0)
                                                                                                                     {
                                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.JoinOnlineGameActivity.resultcode", false);
                                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.JoinOnlineGameActivity.gameid", -1);
                                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.JoinOnlineGameActivity.failurereasoncode", JOINERROR_BADPASS);
                                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                                                                     sendBroadcast(broadcastintent);
                                                                                                                                     stopSelf(servid);
                                                                                                                     }
                                                                                                                     else
                                                                                                                     {
                                                                                                                                     if (result.indexOf("here") == 0)
                                                                                                                                     {
                                                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.JoinOnlineGameActivity.resultcode", false);
                                                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.JoinOnlineGameActivity.gameid", -1);
                                                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.JoinOnlineGameActivity.failurereasoncode", JOINERROR_CONTINUE);
                                                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                                                                                     sendBroadcast(broadcastintent);
                                                                                                                                                     stopSelf(servid);
                                                                                                                                     }
                                                                                                                                     else
                                                                                                                                     {
                                                                                                                                                     int resultcode = 0;
                                                                                                                                                     try
                                                                                                                                                     {
                                                                                                                                                                     resultcode = Integer.decode(result);
                                                                                                                                                     }
                                                                                                                                                     catch (Exception e)
                                                                                                                                                     {
                                                                                                                                                                     // unspecified error....
                                                                                                                                                     }
                                                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.JoinOnlineGameActivity.resultcode", false);
                                                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.JoinOnlineGameActivity.gameid", -1);
                                                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.JoinOnlineGameActivity.failurereasoncode", resultcode);
                                                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.JoinOnlineGameActivity.teaminfo", teaminfo);
                                                                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                                                                                     sendBroadcast(broadcastintent);
                                                                                                                                                     stopSelf(servid);
                                                                                                                                     }
                                                                                                                     }
                                                                                                     }
                                                                                     }

                                                                     }
                                                     }).start();
                                     }
                     }

                     if (action.equals("com.lloydm.geosword.common.UploadService.makenewgame"))
                     {
                                     // we want to upload the game data to the website in order to create
                                     // a new game...
                                     // if we are successful then broadcast 'true' to the activity that
                                     // called us.....
                                     final int servid = startId;
                                     final int numteams = intent.getIntExtra("com.lloydm.geosword.common.UploadService.numteams", 0);
                                     final int numfleets = intent.getIntExtra("com.lloydm.geosword.common.UploadService.numfleets", 0);
                                     final int minexp = intent.getIntExtra("com.lloydm.geosword.common.UploadService.minexp", 0);
                                     final int maxexp = intent.getIntExtra("com.lloydm.geosword.common.UploadService.maxexp", 0);
                                     final int maxplayers = intent.getIntExtra("com.lloydm.geosword.common.UploadService.maxplayers", 0);
                                     final int gameprivate = intent.getIntExtra("com.lloydm.geosword.common.UploadService.gameprivate", 0);
                                     // final long enddate =
                                     // intent.getLongExtra("com.lloydm.geosword.common.UploadService.enddate",0);
                                     final String gamename = intent.getStringExtra("com.lloydm.geosword.common.UploadService.gamename");
                                     String gamepassword = "";
                                     if (gameprivate == 1)
                                     {
                                                     gamepassword = intent.getStringExtra("com.lloydm.geosword.common.UploadService.gamepassword");

                                     }
                                     final String password = gamepassword;

                                     new Thread(new Runnable()
                                     {
                                                     @Override
                                                     public void
run()
                                                     {
                                                                     getuser();
                                                                     if (notloggedin())
                                                                     {
                                                                                     // return a fail result
                                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.CreateOnlineGameActivity.makenewgame");
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.CreateOnlineGameActivity.resultcode", false);
                                                                                     if (weberror)
                                                                                     {
                                                                                                     // most likely a connection failure of some sort...
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.CreateOnlineGameActivity.authenticationerror", LOGIN_WEB_ERROR);
                                                                                     }
                                                                                     else
                                                                                     {
                                                                                                     // appears that the user may not actually have a
                                                                                                     // login....or at least those credentials are
                                                                                                     // wrong....
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.CreateOnlineGameActivity.authenticationerror", LOGIN_NOT_FOUND);
                                                                                     }
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                     sendBroadcast(broadcastintent);
                                                                                     stopSelf(servid);
                                                                                     return;
                                                                     }

                                                                     // while testing...

                                                                     String url = URL_NEWGAME + "numteams=" + numteams + "&numfleets=" + numfleets + "&minexp=" + minexp + "&maxexp=" + maxexp + "&maxplayers=" + maxplayers + "&gameprivate=" + gameprivate + "&enddate=7&mytime=7&gamename=" + Uri.encode(gamename);
                                                                     url = url + "&encodedusername=" + encodedusername + "&encodeduserpass=" + encodeduserpass;
                                                                     if (!password.equals(""))
                                                                     {
                                                                                     url = url + "&gamepassword=" + Uri.encode(password);
                                                                     }

                                                                     final String result = HTTPGet.GetURL(url);
                                                                     Log.d(TAG, "create game - result:" + result);
                                                                     int gameid = -1;
                                                                     if (result.contains(":"))
                                                                     {
                                                                                     gameid = 1;
                                                                                     // some further checking would be good....looking a
                                                                                     // valid key etc...
                                                                     }
                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.CreateOnlineGameActivity.makenewgame");
                                                                     if (gameid != -1)
                                                                     {
                                                                                     // all good! we are good to go!
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.CreateOnlineGameActivity.resultcode", true);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.CreateOnlineGameActivity.gameid", result);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                     sendBroadcast(broadcastintent);
                                                                                     stopSelf(servid);
                                                                     }
                                                                     else
                                                                     {
                                                                                     // oh no...something went wrong!
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.CreateOnlineGameActivity.resultcode", false);
                                                                                     if (result.equals("many"))
                                                                                     {
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.CreateOnlineGameActivity.failurereasoncode", CREATEERROR_TOOMANY);
                                                                                     }
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                     sendBroadcast(broadcastintent);
                                                                                     stopSelf(servid);
                                                                     }

                                                     }
                                     }).start();
                     }

                     // in game stuff.....
                     if (action.equals("com.lloydm.geosword.common.UploadService.ingamefrontmenu.getbattles"))
                     {
                                     final int servid = startId;
                                     final int gameid = intent.getIntExtra("com.lloydm.geosword.common.UploadService.gameid", 0);
                                     // final int playerid = intent.getIntExtra("com.lloydm.geosword.common.UploadService.playerid", 0);
                                     final String battlelist = intent.getStringExtra("com.lloydm.geosword.common.UploadService.battlefiles");
                                     final String battledesc = intent.getStringExtra("com.lloydm.geosword.common.UploadService.battlefilesdesc");
                                     Log.i(TAG, "battle list in service:" + battlelist);
                                     if (battlelist != null && battledesc != null)
                                     {
                                                     // download the files....no need to log in at this point...technically should already be logged in...
                                                     // also these files are publicly available anyway.
                                                     Log.i(TAG, "battlelist should not be null");
                                                     new Thread(new Runnable()
                                                     {
                                                                     @Override
                                                                     public void
run()
                                                                     {
                                                                                     final String[] battlefiles = battlelist.split(":");
                                                                                     final String[] battlearraydesc = battledesc.split(":");
                                                                                     Log.i(TAG, "entering battle list thread");
                                                                                     if (battlefiles != null)
                                                                                     {
                                                                                                     Log.i(TAG, "battlefiles not null");
                                                                                                     boolean[] successful = new boolean[battlefiles.length];
                                                                                                     String goodfiles = "";
                                                                                                     String gooddesc = "";
                                                                                                     for (int i = 0; i < battlefiles.length; i++)
                                                                                                     {
                                                                                                                     successful[i] = false;
                                                                                                                     String downloadlink = battlefiles[i];
                                                                                                                     String downloaddesc = battlearraydesc[i];
                                                                                                                     // get each one .. one at a time.....
                                                                                                                     Log.i(TAG, "getfrom web starting");

                                                                                                                     Log.i(TAG, "downloadlink:" + downloadlink);
                                                                                                                     Log.i(TAG, "downloadfrom:" + Config.WEBREPLAYDOWNLOADPATH + downloadlink);
                                                                                                                     if (!downloadlink.equals(""))
                                                                                                                     {
                                                                                                                                     successful[i] = GetFileFromWeb.GetFile(downloadlink, Config.WEBREPLAYDOWNLOADPATH + downloadlink);
                                                                                                                                     if (successful[i])
                                                                                                                                     {
                                                                                                                                                     Log.i(TAG, "successful download");
                                                                                                                                                     goodfiles = goodfiles + downloadlink + ":";
                                                                                                                                                     gooddesc = gooddesc + downloaddesc + ":";
                                                                                                                                     }
                                                                                                                                     else
                                                                                                                                     {
                                                                                                                                                     Log.i(TAG, "unsuccessful download");
                                                                                                                                     }
                                                                                                                     }
                                                                                                     }
                                                                                                     // for each one that was successful return an appropriate result.....
                                                                                                     if (goodfiles.length() > 0)
                                                                                                     {
                                                                                                                     Log.i(TAG, "goodfiles ok");
                                                                                                                     // get the shared prefs and store this value for the gameid....
                                                                                                                     // no broadcast needed actually.....
                                                                                                                     String files = getprefs("com.lloydm.geosword.downloadedbattles_" + gameid, "") + goodfiles;
                                                                                                                     saveprefs("com.lloydm.geosword.downloadedbattles_" + gameid, files);
                                                                                                                     String descs = getprefs("com.lloydm.geosword.downloadedbattlesdesc_" + gameid, "") + gooddesc;
                                                                                                                     saveprefs("com.lloydm.geosword.downloadedbattlesdesc_" + gameid, descs);
                                                                                                                     // all good!
                                                                                                                     Log.i(TAG, "prefs should have saved");
                                                                                                     }
                                                                                                     else
                                                                                                     {
                                                                                                                     Log.i(TAG, "no goodfiles");
                                                                                                     }
                                                                                     }
                                                                                     stopSelf(servid);
                                                                     }
                                                     }).start();
                                     }
                     }
                     if (action.equals("com.lloydm.geosword.common.UploadService.ingamefrontmenu.load"))
                     {
                                     final int gameid = intent.getIntExtra("com.lloydm.geosword.common.UploadService.gameid", 0);
                                     final int playerid = intent.getIntExtra("com.lloydm.geosword.common.UploadService.playerid", 0);
                                     final int servid = startId;
                                     // get the starmap, time remaining and any available news.

                                     // get the battle list for this user as well...any battles they are involved in....

                                     new Thread(new Runnable()
                                     {
                                                     @Override
                                                     public void
run()
                                                     {
                                                                     getuser();
                                                                     if (notloggedin())
                                                                     {
                                                                                     // return a fail result
                                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.InGameFrontMenuActivity.load");
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.InGameFrontMenuActivity.resultcode", false);
                                                                                     if (weberror)
                                                                                     {
                                                                                                     // most likely a connection failure of some sort...
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.InGameFrontMenuActivity.authenticationerror", LOGIN_WEB_ERROR);
                                                                                     }
                                                                                     else
                                                                                     {
                                                                                                     // appears that the user may not actually have a
                                                                                                     // login....or at least those credentials are
                                                                                                     // wrong....
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.InGameFrontMenuActivity.authenticationerror", LOGIN_NOT_FOUND);
                                                                                     }
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                     sendBroadcast(broadcastintent);
                                                                                     stopSelf(servid);
                                                                                     return;
                                                                     }

                                                                     String url = URL_GETSTARMAP + "gameid=" + gameid;
                                                                     url = url + "&encodedusername=" + encodedusername + "&encodeduserpass=" + encodeduserpass;
                                                                     String starmapresult = HTTPGet.GetURL(url);
                                                                     Log.d(TAG, "get starmap - result:" + starmapresult);

                                                                     url = URL_GETBATTLEDOWNLOADLINKS + "GID=" + gameid + "&PID=" + playerid;
                                                                     url = url + "&encodedusername=" + encodedusername + "&encodeduserpass=" + encodeduserpass;

                                                                     String battlelist = HTTPGet.GetURL(url);
                                                                     Log.d(TAG, "Battle list - result:" + battlelist);

                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.InGameFrontMenuActivity.load");

                                                                     if (starmapresult.equals(""))// || timeremainingresult.equals("") || isnewsresult.equals("") || isresearchresult.equals(""))
                                                                     {
                                                                                     // website error most likely...
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.InGameFrontMenuActivity.resultcode", false);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.InGameFrontMenuActivity.failurereasoncode", NETWORK_GENERALERROR);
                                                                     }
                                                                     else
                                                                     {
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.InGameFrontMenuActivity.resultcode", true);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.InGameFrontMenuActivity.starmap", starmapresult);
                                                                                     // broadcastintent.putExtra("com.lloydm.geosword.activities.InGameFrontMenuActivity.timeleft", timeremainingresult);
                                                                                     // broadcastintent.putExtra("com.lloydm.geosword.activities.InGameFrontMenuActivity.isnews", isnewsresult);
                                                                                     // broadcastintent.putExtra("com.lloydm.geosword.activities.InGameFrontMenuActivity.isresearch", isresearchresult);
                                                                                     if (!battlelist.equals(""))
                                                                                     {
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.InGameFrontMenuActivity.battlelist", battlelist);
                                                                                     }

                                                                     }
                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                     sendBroadcast(broadcastintent);
                                                                     stopSelf(servid);

                                                     }
                                     }).start();

                     }
                     if (action.equals("com.lloydm.geosword.common.UploadService.inspectfleet.load"))
                     {
                                     // get fleet info....
                                     final int playerid = intent.getIntExtra("com.lloydm.geosword.common.UploadService.playerid", 0);
                                     final int servid = startId;
                                     new Thread(new Runnable()
                                     {
                                                     @Override
                                                     public void
run()
                                                     {
                                                                     getuser();
                                                                     if (notloggedin())
                                                                     {
                                                                                     // return a fail result
                                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.InspectFleetActivity.load");
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.InspectFleetActivity.resultcode", false);
                                                                                     if (weberror)
                                                                                     {
                                                                                                     // most likely a connection failure of some sort...
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.InspectFleetActivity.authenticationerror", LOGIN_WEB_ERROR);
                                                                                     }
                                                                                     else
                                                                                     {
                                                                                                     // appears that the user may not actually have a
                                                                                                     // login....or at least those credentials are
                                                                                                     // wrong....
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.InspectFleetActivity.authenticationerror", LOGIN_NOT_FOUND);
                                                                                     }
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                     sendBroadcast(broadcastintent);
                                                                                     stopSelf(servid);
                                                                                     return;
                                                                     }

                                                                     String url = URL_GETFLEETINFO + "ID=" + playerid;

                                                                     url = url + "&encodedusername=" + encodedusername + "&encodeduserpass=" + encodeduserpass;
                                                                     String fleetresult = HTTPGet.GetURL(url);
                                                                     Log.d(TAG, "fleet - result:" + fleetresult);
                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.InspectFleetActivity.load");
                                                                     if (fleetresult.equals(""))
                                                                     {
                                                                                     // website error most likely...
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.InspectFleetActivity.resultcode", false);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.InspectFleetActivity.failurereasoncode", NETWORK_GENERALERROR);
                                                                     }
                                                                     else
                                                                     {
                                                                                     if (fleetresult.contains(":"))
                                                                                     {
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.InspectFleetActivity.resultcode", true);
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.InspectFleetActivity.fleetinfo", fleetresult);
                                                                                     }
                                                                                     else
                                                                                     {
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.InspectFleetActivity.resultcode", false);
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.InspectFleetActivity.failurereasoncode", NETWORK_GENERALERROR);
                                                                                     }
                                                                     }
                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                     sendBroadcast(broadcastintent);
                                                                     stopSelf(servid);

                                                     }
                                     }).start();

                     }
                     /*
                         * if (action.equals("com.lloydm.geosword.common.UploadService.inspectfleet.update")) { // update fleet info final int playerid =
                         * intent.getIntExtra("com.lloydm.geosword.common.UploadService.playerid", 0); final int gameid = intent.getIntExtra("com.lloydm.geosword.common.UploadService.gameid", 0); final int fleetid =
                         * intent.getIntExtra("com.lloydm.geosword.common.UploadService.fleetid", 0); final int shipid = intent.getIntExtra("com.lloydm.geosword.common.UploadService.shipid", 0); final int groupid =
                         * intent.getIntExtra("com.lloydm.geosword.common.UploadService.aigroupid", 0); final String fleetname = intent.getStringExtra("com.lloydm.geosword.common.UploadService.fleetname");
                         *
                         * new Thread(new Runnable() {
                         *
                         * @Override public void run() { getuser(); if (notloggedin()) { // return a fail result Intent broadcastintent = new Intent("com.lloydm.geosword.activities.InspectFleetActivity.update");
                         * broadcastintent.putExtra("com.lloydm.geosword.activities.InspectFleetActivity.resultcode", false); if (weberror) { // most likely a connection failure of some sort...
                         * broadcastintent.putExtra("com.lloydm.geosword.activities.InspectFleetActivity.authenticationerror", LOGIN_WEB_ERROR); } else { // appears that the user may not actually have a //
                         * login....or at least those credentials are // wrong.... broadcastintent.putExtra("com.lloydm.geosword.activities.InspectFleetActivity.authenticationerror", LOGIN_NOT_FOUND); }
                         * broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid); sendBroadcast(broadcastintent);
                         *
                         * return; }
                         *
                         * String url = URL_UPDATEFLEETINFO + "PID=" + playerid + "&GID=" + gameid + "&FID=" + fleetid + "&SID=" + shipid + "&GPID=" + groupid + "&FNAME=" + Uri.encode(fleetname); url = url +
                         * "&encodedusername=" + encodedusername + "&encodeduserpass=" + encodeduserpass; String fleetresult = HTTPGet.GetURL(url); Log.d(TAG, "update fleet - result:" + fleetresult); Intent
                         * broadcastintent = new Intent("com.lloydm.geosword.activities.InspectFleetActivity.update"); if (!fleetresult.equals("T")) { // website error most likely...
                         * broadcastintent.putExtra("com.lloydm.geosword.activities.InspectFleetActivity.resultcode", false);
                         * broadcastintent.putExtra("com.lloydm.geosword.activities.InspectFleetActivity.failurereasoncode", NETWORK_GENERALERROR); } else {
                         * broadcastintent.putExtra("com.lloydm.geosword.activities.InspectFleetActivity.resultcode", true);
                         * broadcastintent.putExtra("com.lloydm.geosword.activities.InspectFleetActivity.updatefleetinfo", true); } broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                         * sendBroadcast(broadcastintent);
                         *
                         * } })
.start();
                         *
                         * }
                         *
/
                     /*
                         * if (action.equals("com.lloydm.geosword.common.UploadService.research.load")) { // get the research info final int playerid =
                         * intent.getIntExtra("com.lloydm.geosword.common.UploadService.playerid", 0);
                         *
                         * new Thread(new Runnable() {
                         *
                         * @Override public void run() { getuser(); if (notloggedin()) { // return a fail result Intent broadcastintent = new Intent("com.lloydm.geosword.activities.ResearchActivity.load");
                         * broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.resultcode", false); if (weberror) { // most likely a connection failure of some sort...
                         * broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.authenticationerror", LOGIN_WEB_ERROR); } else { // appears that the user may not actually have a // login....or at
                         * least those credentials are // wrong.... broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.authenticationerror", LOGIN_NOT_FOUND); }
                         * broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid); sendBroadcast(broadcastintent);
                         *
                         * return; }
                         *
                         * String url = URL_GETRESEARCHINFO + "ID=" + playerid; url = url + "&encodedusername=" + encodedusername + "&encodeduserpass=" + encodeduserpass; String result = HTTPGet.GetURL(url);
                         * Log.d(TAG, "research info - result:" + result); Intent broadcastintent = new Intent("com.lloydm.geosword.activities.ResearchActivity.load"); if (result.equals("")) { // website error most
                         * likely... broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.resultcode", false);
                         * broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.failurereasoncode", NETWORK_GENERALERROR); } else {
                         * broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.resultcode", true); broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.researchinfo",
                         * result)
; } broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid); sendBroadcast(broadcastintent);
                         *
                         * } })
.start();
                         *
                         * }
                         *
/
                     if (action.equals("com.lloydm.geosword.common.UploadService.research.load2"))
                     {
                                     // get the research info
                                     final int playerid = intent.getIntExtra("com.lloydm.geosword.common.UploadService.playerid", 0);
                                     final int servid = startId;
                                     new Thread(new Runnable()
                                     {
                                                     @Override
                                                     public void
run()
                                                     {
                                                                     getuser();
                                                                     if (notloggedin())
                                                                     {
                                                                                     // return a fail result
                                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.ResearchActivity.load");
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.resultcode", false);
                                                                                     if (weberror)
                                                                                     {
                                                                                                     // most likely a connection failure of some sort...
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.authenticationerror", LOGIN_WEB_ERROR);
                                                                                     }
                                                                                     else
                                                                                     {
                                                                                                     // appears that the user may not actually have a
                                                                                                     // login....or at least those credentials are
                                                                                                     // wrong....
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.authenticationerror", LOGIN_NOT_FOUND);
                                                                                     }
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                     sendBroadcast(broadcastintent);
                                                                                     stopSelf(servid);
                                                                                     return;
                                                                     }

                                                                     String url = URL_GETRESEARCHINFO2 + "ID=" + playerid;
                                                                     url = url + "&encodedusername=" + encodedusername + "&encodeduserpass=" + encodeduserpass;
                                                                     String result = HTTPGet.GetURL(url);
                                                                     Log.d(TAG, "research info - result:" + result);
                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.ResearchActivity.load");
                                                                     if (result.equals(""))
                                                                     {
                                                                                     // website error most likely...
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.resultcode", false);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.failurereasoncode", NETWORK_GENERALERROR);
                                                                     }
                                                                     else
                                                                     {
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.resultcode", true);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.researchinfo", result);
                                                                     }
                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                     sendBroadcast(broadcastintent);
                                                                     stopSelf(servid);

                                                     }
                                     }).start();
                     }
                     if (action.equals("com.lloydm.geosword.common.UploadService.research.update2"))
                     {
                                     // update research
                                     final int servid = startId;
                                     final int playerid = intent.getIntExtra("com.lloydm.geosword.common.UploadService.playerid", 0);
                                     final String researchid = intent.getStringExtra("com.lloydm.geosword.common.UploadService.researchid");
                                     new Thread(new Runnable()
                                     {
                                                     @Override
                                                     public void
run()
                                                     {
                                                                     getuser();
                                                                     if (notloggedin())
                                                                     {
                                                                                     // return a fail result
                                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.ResearchActivity.update");
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.resultcode", false);
                                                                                     if (weberror)
                                                                                     {
                                                                                                     // most likely a connection failure of some sort...
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.authenticationerror", LOGIN_WEB_ERROR);
                                                                                     }
                                                                                     else
                                                                                     {
                                                                                                     // appears that the user may not actually have a
                                                                                                     // login....or at least those credentials are
                                                                                                     // wrong....
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.authenticationerror", LOGIN_NOT_FOUND);
                                                                                     }
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                     sendBroadcast(broadcastintent);
                                                                                     stopSelf(servid);
                                                                                     return;
                                                                     }
                                                                     String url = URL_UPDATERESEARCH2 + "PID=" + playerid + "&RID=" + researchid;
                                                                     url = url + "&encodedusername=" + encodedusername + "&encodeduserpass=" + encodeduserpass;
                                                                     String result = HTTPGet.GetURL(url);
                                                                     Log.d(TAG, "update research - result:" + result);
                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.ResearchActivity.update");
                                                                     boolean tmp = false;
                                                                     for (int ii = 0; ii < 16; ii++)
                                                                     {
                                                                                     if (result.equals(Integer.toString(ii)))
                                                                                     {
                                                                                                     tmp = true;
                                                                                     }
                                                                     }
                                                                     // if(result.equals("A") || result.equals("B") ||
                                                                     // result.equals("C") || result.equals("D") ||
                                                                     // result.equals("E") || result.equals("F"))
                                                                     // {
                                                                     // tmp = true;
                                                                     // }
                                                                     if (tmp || result.equals("-1"))

                                                                     {
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.resultcode", true);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.researchupdated", true);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.researchid", Integer.decode(result));
                                                                     }
                                                                     else
                                                                     {
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.resultcode", false);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.failurereasoncode", NETWORK_GENERALERROR);
                                                                     }
                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                     sendBroadcast(broadcastintent);
                                                                     stopSelf(servid);
                                                     }
                                     }).start();
                     }
                     /*
                         * if (action.equals("com.lloydm.geosword.common.UploadService.research.update")) { // update research final int playerid =
                         * intent.getIntExtra("com.lloydm.geosword.common.UploadService.playerid", 0); final int researchid = intent.getIntExtra("com.lloydm.geosword.common.UploadService.researchid", 0); final int
                         * mode = intent.getIntExtra("com.lloydm.geosword.common.UploadService.researchmode", 0);
                         *
                         * new Thread(new Runnable() {
                         *
                         * @Override public void run() { getuser(); if (notloggedin()) { // return a fail result Intent broadcastintent = new Intent("com.lloydm.geosword.activities.ResearchActivity.update");
                         * broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.resultcode", false); if (weberror) { // most likely a connection failure of some sort...
                         * broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.authenticationerror", LOGIN_WEB_ERROR); } else { // appears that the user may not actually have a // login....or at
                         * least those credentials are // wrong.... broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.authenticationerror", LOGIN_NOT_FOUND); }
                         * broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid); sendBroadcast(broadcastintent);
                         *
                         * return; }
                         *
                         * String url = URL_UPDATERESEARCH + "PID=" + playerid + "&RID=" + researchid + "&MODE=" + mode; url = url + "&encodedusername=" + encodedusername + "&encodeduserpass=" + encodeduserpass;
                         * String result = HTTPGet.GetURL(url); Log.d(TAG, "update research - result:" + result); Intent broadcastintent = new Intent("com.lloydm.geosword.activities.ResearchActivity.update");
                         *
                         * if (!result.equals("T")) { if (result.equals("F")) { // invalid research type..... broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.resultcode", true);
                         * broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.researchupdated", false); broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.researchid",
                         * researchid)
; broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.mode", mode);
                         *
                         * } else { // website error most likely... broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.resultcode", false);
                         * broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.failurereasoncode", NETWORK_GENERALERROR); } } else {
                         * broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.resultcode", true); broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.researchupdated",
                         * true)
; broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.researchid", researchid); broadcastintent.putExtra("com.lloydm.geosword.activities.ResearchActivity.mode",
                         * mode)
;
                         *
                         * } broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid); sendBroadcast(broadcastintent);
                         *
                         * } })
.start();
                         *
                         * } /* if (action.equals("com.lloydm.geosword.common.UploadService.communications.load")) { // get the news // get the research info final int playerid =
                         * intent.getIntExtra("com.lloydm.geosword.common.UploadService.playerid", 0);
                         *
                         * new Thread(new Runnable() {
                         *
                         * @Override public void run() { getuser(); if (notloggedin()) { // return a fail result Intent broadcastintent = new Intent("com.lloydm.geosword.activities.NewsFeedActivity.load");
                         * broadcastintent.putExtra("com.lloydm.geosword.activities.NewsFeedActivity.resultcode", false); if (weberror) { // most likely a connection failure of some sort...
                         * broadcastintent.putExtra("com.lloydm.geosword.activities.NewsFeedActivity.authenticationerror", LOGIN_WEB_ERROR); } else { // appears that the user may not actually have a // login....or at
                         * least those credentials are // wrong.... broadcastintent.putExtra("com.lloydm.geosword.activities.NewsFeedActivity.authenticationerror", LOGIN_NOT_FOUND); }
                         * broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid); sendBroadcast(broadcastintent);
                         *
                         * return; }
                         *
                         * String url = URL_GETNEWS + "ID=" + playerid; url = url + "&encodedusername=" + encodedusername + "&encodeduserpass=" + encodeduserpass; String result = HTTPGet.GetURL(url); Log.d(TAG,
                         * "get news - result:" + result)
; Intent broadcastintent = new Intent("com.lloydm.geosword.activities.NewsFeedActivity.load"); if (result.equals("")) { // website error most likely...
                         * broadcastintent.putExtra("com.lloydm.geosword.activities.NewsFeedActivity.resultcode", false); broadcastintent.putExtra("com.lloydm.geosword.activities.NewsFeedActivity.failurereasoncode",
                         * NETWORK_GENERALERROR)
; } else { broadcastintent.putExtra("com.lloydm.geosword.activities.NewsFeedActivity.resultcode", true);
                         * broadcastintent.putExtra("com.lloydm.geosword.activities.NewsFeedActivity.newsfeed", result); } broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                         * sendBroadcast(broadcastintent);
                         *
                         * } })
.start();
                         *
                         * } if (action.equals("com.lloydm.geosword.common.UploadService.communications.update")) { // create news - NOT IN USE YET }
                         *
/
                     // on the fleet screen.......
                     if (action.equals("com.lloydm.geosword.common.UploadService.launchattack.load"))
                     {
                                     // get the potential fleets as targets and the starmap....
                                     final int playerid = intent.getIntExtra("com.lloydm.geosword.common.UploadService.playerid", 0);
                                     final int gameid = intent.getIntExtra("com.lloydm.geosword.common.UploadService.gameid", 0);
                                     final int servid = startId;
                                     // final int fleetatt =
                                     // intent.getIntExtra("com.lloydm.geosword.common.UploadService.myfleetid",0);
                                     // final int fleetdef =
                                     // intent.getIntExtra("com.lloydm.geosword.common.UploadService.enemyfleetid",0);

                                     new Thread(new Runnable()
                                     {
                                                     @Override
                                                     public void
run()
                                                     {
                                                                     getuser();
                                                                     if (notloggedin())
                                                                     {
                                                                                     // return a fail result
                                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.LaunchAttackActivity.load");
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.LaunchAttackActivity.resultcode", false);
                                                                                     if (weberror)
                                                                                     {
                                                                                                     // most likely a connection failure of some sort...
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.LaunchAttackActivity.authenticationerror", LOGIN_WEB_ERROR);
                                                                                     }
                                                                                     else
                                                                                     {
                                                                                                     // appears that the user may not actually have a
                                                                                                     // login....or at least those credentials are
                                                                                                     // wrong....
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.LaunchAttackActivity.authenticationerror", LOGIN_NOT_FOUND);
                                                                                     }
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                     sendBroadcast(broadcastintent);
                                                                                     stopSelf(servid);
                                                                                     return;
                                                                     }

                                                                     // Log.d(TAG,"playerid="+playerid);
                                                                     String url = URL_GETPOTENTIALFLEETSTOATTACK + "ID=" + playerid;
                                                                     url = url + "&encodedusername=" + encodedusername + "&encodeduserpass=" + encodeduserpass;
                                                                     // Log.d(TAG,"url="+url);
                                                                     String targetsresult = HTTPGet.GetURL(url);
                                                                     Log.d(TAG, "get targets - result:" + targetsresult);
                                                                     url = URL_GETSTARMAP + "gameid=" + gameid;
                                                                     url = url + "&encodedusername=" + encodedusername + "&encodeduserpass=" + encodeduserpass;
                                                                     String starmapresult = HTTPGet.GetURL(url);
                                                                     Log.d(TAG, "starmap - result:" + starmapresult);

                                                                     url = URL_GETTEAMS + "GID=" + gameid;
                                                                     url = url + "&encodedusername=" + encodedusername + "&encodeduserpass=" + encodeduserpass;
                                                                     String teamnameresult = HTTPGet.GetURL(url);
                                                                     Log.d(TAG, "starmap - result:" + teamnameresult);

                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.LaunchAttackActivity.load");
                                                                     if (starmapresult.equals(""))
                                                                     {
                                                                                     // website error most likely...
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.LaunchAttackActivity.resultcode", false);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.LaunchAttackActivity.failurereasoncode", NETWORK_GENERALERROR);
                                                                     }
                                                                     else
                                                                     {
                                                                                     if (targetsresult.equals(""))
                                                                                     {
                                                                                                     targetsresult = "none";
                                                                                     }
                                                                                     if (teamnameresult.equals(""))
                                                                                     {
                                                                                                     teamnameresult = "none";
                                                                                     }
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.LaunchAttackActivity.resultcode", true);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.LaunchAttackActivity.attacktargets", targetsresult);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.LaunchAttackActivity.starmap", starmapresult);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.LaunchAttackActivity.callsigns", teamnameresult);
                                                                     }
                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                     sendBroadcast(broadcastintent);
                                                                     stopSelf(servid);
                                                     }
                                     }).start();
                     }
                     if (action.equals("com.lloydm.geosword.common.UploadService.launchattack.update"))
                     {
                                     // launch attack / attack target / get result
                                     final int fleetatt = intent.getIntExtra("com.lloydm.geosword.common.UploadService.myfleetid", 0);
                                     final int fleetdef = intent.getIntExtra("com.lloydm.geosword.common.UploadService.enemyfleetid", 0);
                                     final int xcoord = intent.getIntExtra("com.lloydm.geosword.common.UploadService.xcoord", -1);
                                     final int ycoord = intent.getIntExtra("com.lloydm.geosword.common.UploadService.ycoord", -1);
                                     final int servid = startId;

                                     Log.i(TAG, "Begin Launch Attack:0s");
                                     final long starttiming = System.currentTimeMillis();

                                     new Thread(new Runnable()
                                     {
                                                     @Override
                                                     public void
run()
                                                     {
                                                                     getuser();
                                                                     if (notloggedin())
                                                                     {
                                                                                     // return a fail result
                                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.LaunchAttackActivity.update");
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.LaunchAttackActivity.resultcode", false);
                                                                                     if (weberror)
                                                                                     {
                                                                                                     // most likely a connection failure of some sort...
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.LaunchAttackActivity.authenticationerror", LOGIN_WEB_ERROR);
                                                                                     }
                                                                                     else
                                                                                     {
                                                                                                     // appears that the user may not actually have a
                                                                                                     // login....or at least those credentials are
                                                                                                     // wrong....
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.LaunchAttackActivity.authenticationerror", LOGIN_NOT_FOUND);
                                                                                     }
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                     sendBroadcast(broadcastintent);
                                                                                     stopSelf(servid);
                                                                                     return;
                                                                     }

                                                                     // while testing battles.....easiest way with minimal
                                                                     // coding...and I get to watch some battles too!
                                                                     // and see the results!
                                                                     String result = "";
                                                                     String url = URL_LAUNCHATTACK + "FA=" + fleetatt + "&FD=" + fleetdef;
                                                                     url = url + "&encodedusername=" + encodedusername + "&encodeduserpass=" + encodeduserpass;
                                                                     Log.d(TAG, "url=" + url);
                                                                     result = HTTPGet.GetURL(url);
                                                                     Log.d(TAG, "launch attack - result:" + result);

                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.LaunchAttackActivity.update");
                                                                     boolean successful = false;
                                                                     String filetoupload = "";
                                                                     String battleoutcome = "";
                                                                     if (result.equals(""))
                                                                     {
                                                                                     // website error most likely...
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.LaunchAttackActivity.resultcode", false);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.LaunchAttackActivity.failurereasoncode", NETWORK_GENERALERROR);
                                                                     }
                                                                     else
                                                                     {

                                                                                     // int attresult = 0;
                                                                                     if (result.equals("A0"))
                                                                                     {
                                                                                                     // no battle as all our ships were defeated in a battle as we spoke!
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.LaunchAttackActivity.resultcode", true);
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.LaunchAttackActivity.attresult", "A0");
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                                     sendBroadcast(broadcastintent);
                                                                                                     stopSelf(servid);
                                                                                                     return;
                                                                                     }
                                                                                     if (result.equals("D0"))
                                                                                     {
                                                                                                     // no battle as the enemy fleet was defeated by someone else!
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.LaunchAttackActivity.resultcode", true);
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.LaunchAttackActivity.attresult", "D0");
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                                     sendBroadcast(broadcastintent);
                                                                                                     stopSelf(servid);
                                                                                                     return;
                                                                                     }
                                                                                     String attships = "";
                                                                                     String battlefile = "";
                                                                                     String battleresult = "";
                                                                                     // run the simulation!
                                                                                     long elapsedtime = System.currentTimeMillis() - starttiming;
                                                                                     if (elapsedtime > 1000)
                                                                                     {
                                                                                                     Log.i(TAG, "Time taken to retrieve db info:" + (elapsedtime / 1000) + "s.");
                                                                                     }
                                                                                     else
                                                                                     {
                                                                                                     Log.i(TAG, "Time taken to retrieve db info:less than 1 second.");
                                                                                     }
                                                                                     Log.d(TAG, "Got to here - battle needs calculating....");

                                                                                     // String suggestedfilepath = "";
                                                                                     // Simulator sim = new
                                                                                     // Simulator(result,suggestedfilepath);

                                                                                     // for now do locally.....
                                                                                     String opath = Config.getStorageFolder(UploadService.this);
                                                                                     Simulator sim = new Simulator(result, opath, UploadService.this, false);
                                                                                     battlefile = sim.getBattleFile();
                                                                                     battleresult = sim.getBattleResult();
                                                                                     if (battleresult.length() > 0)
                                                                                     {
                                                                                                     battleresult = battleresult + Integer.toString(xcoord) + Integer.toString(ycoord);
                                                                                     }
                                                                                     // then upload this to the database.......(at least
                                                                                     // the result anyway!)

                                                                                     elapsedtime = System.currentTimeMillis() - starttiming - elapsedtime;
                                                                                     if (elapsedtime > 1000)
                                                                                     {
                                                                                                     Log.i(TAG, "Time taken to calculate simulation result:" + (elapsedtime / 1000) + "s.");
                                                                                     }
                                                                                     else
                                                                                     {
                                                                                                     Log.i(TAG, "Time taken to calculate simulation result:less than 1 second.");
                                                                                     }

                                                                                     String result2 = "";
                                                                                     String url2 = URL_UPLOADBATTLERESULT + "FA=" + fleetatt + "&FD=" + fleetdef + "&RS=" + battleresult;
                                                                                     url2 = url2 + "&encodedusername=" + encodedusername + "&encodeduserpass=" + encodeduserpass;
                                                                                     Log.d(TAG, "url2=" + url2);
                                                                                     result2 = HTTPGet.GetURL(url2);
                                                                                     Log.d(TAG, "battle result server response:" + result2);

                                                                                     // assuming result2 comes back okay....then we are
                                                                                     // good to go!
                                                                                     elapsedtime = System.currentTimeMillis() - starttiming - elapsedtime;
                                                                                     if (elapsedtime > 1000)
                                                                                     {
                                                                                                     Log.i(TAG, "Time taken to upload simulation result:" + (elapsedtime / 1000) + "s.");
                                                                                     }
                                                                                     else
                                                                                     {
                                                                                                     Log.i(TAG, "Time taken to upload simulation result:less than 1 second.");
                                                                                     }

                                                                                     if (result2.equals("T")) // signals that all went
                                                                                                                                                                                         // okay....
                                                                                     {
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.LaunchAttackActivity.resultcode", true);
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.LaunchAttackActivity.attresult", battleresult);
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.LaunchAttackActivity.attships", attships);
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.LaunchAttackActivity.battlefile", battlefile);
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.LaunchAttackActivity.elapsedtime", elapsedtime);

                                                                                                     // at this point we want to also transfer the
                                                                                                     // file to the server.....as an upload.....

                                                                                                     // however we want to do so after we've sent the
                                                                                                     // broadcast....
                                                                                                     successful = true;
                                                                                                     filetoupload = battlefile;
                                                                                                     battleoutcome = battleresult;

                                                                                     }
                                                                                     else
                                                                                     {
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.LaunchAttackActivity.resultcode", false);
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.LaunchAttackActivity.failurereasoncode", NETWORK_GENERALERROR);
                                                                                     }
                                                                                     // calculate the key frames and return the
                                                                                     // result....etc.....
                                                                                     // url =
                                                                                     // URL_UPLOADBATTLE+"FA="+fleetatt+"&FD="+fleetdef+"&R="+attresult+"&AARS="+attships;
                                                                                     // url = url +
                                                                                     // "&encodedusername="+encodedusername+"&encodeduserpass="+encodeduserpass;
                                                                                     // result = HTTPGet.GetURL(url);
                                                                                     // Log.d(TAG,"send battle - result:"+result);
                                                                                     /*
                                                                                         * if(result.equals("T")) //actually not........ { broadcastintent.putExtra( "com.lloydm.geosword.activities.LaunchAttackActivity.resultcode" ,true); broadcastintent.putExtra(
                                                                                         * "com.lloydm.geosword.activities.LaunchAttackActivity.attresult" ,attresult)
; broadcastintent.putExtra( "com.lloydm.geosword.activities.LaunchAttackActivity.attships"
                                                                                         * ,attships)
; broadcastintent.putExtra( "com.lloydm.geosword.activities.LaunchAttackActivity.battlefile" ,battlefile); } else { broadcastintent.putExtra(
                                                                                         * "com.lloydm.geosword.activities.LaunchAttackActivity.resultcode" ,false)
; broadcastintent.putExtra( "com.lloydm.geosword.activities.LaunchAttackActivity.failurereasoncode"
                                                                                         * ,NETWORK_GENERALERROR)
; }
                                                                                         */
                                                                     }
                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                     sendBroadcast(broadcastintent);
                                                                     if (successful)
                                                                     {
                                                                                     // send the file....
                                                                                     long elapsedtime = System.currentTimeMillis() - starttiming;
                                                                                     sendthefile(filetoupload, fleetatt, fleetdef, battleoutcome);
                                                                                     elapsedtime = System.currentTimeMillis() - starttiming - elapsedtime;
                                                                                     if (elapsedtime > 1000)
                                                                                     {
                                                                                                     Log.i(TAG, "Time taken to upload replay:" + (elapsedtime / 1000) + "s.");
                                                                                     }
                                                                                     else
                                                                                     {
                                                                                                     Log.i(TAG, "Time taken to upload replay:less than 1 second.");
                                                                                     }
                                                                     }

                                                                     stopSelf(servid);
                                                     }
                                     }).start();
                     }
                     if (action.equals("com.lloydm.geosword.common.UploadService.shipdetails.load"))
                     {
                                     // get the shipinfo, list weapons, get current ship weapons
                                     final int shipid = intent.getIntExtra("com.lloydm.geosword.common.UploadService.shipid", 0);
                                     // final int shiptypeid = intent.getIntExtra("com.lloydm.geosword.common.UploadService.shiptypeid", 0);
                                     final int servid = startId;
                                     new Thread(new Runnable()
                                     {
                                                     @Override
                                                     public void
run()
                                                     {
                                                                     getuser();
                                                                     if (notloggedin())
                                                                     {
                                                                                     // return a fail result
                                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.ShipActivity.load");
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ShipActivity.resultcode", false);
                                                                                     if (weberror)
                                                                                     {
                                                                                                     // most likely a connection failure of some sort...
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ShipActivity.authenticationerror", LOGIN_WEB_ERROR);
                                                                                     }
                                                                                     else
                                                                                     {
                                                                                                     // appears that the user may not actually have a
                                                                                                     // login....or at least those credentials are
                                                                                                     // wrong....
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ShipActivity.authenticationerror", LOGIN_NOT_FOUND);
                                                                                     }
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                     sendBroadcast(broadcastintent);
                                                                                     stopSelf(servid);
                                                                                     return;
                                                                     }

                                                                     String url = URL_GETSHIPINFO + "ID=" + shipid;
                                                                     url = url + "&encodedusername=" + encodedusername + "&encodeduserpass=" + encodeduserpass;
                                                                     String result = HTTPGet.GetURL(url);
                                                                     Log.d(TAG, "get ship info - result:" + result);
                                                                     url = URL_GETSHIPARMAMENTS + "ID=" + shipid;
                                                                     url = url + "&encodedusername=" + encodedusername + "&encodeduserpass=" + encodeduserpass;
                                                                     String weaponsresult = HTTPGet.GetURL(url);
                                                                     Log.d(TAG, "weapons - result:" + weaponsresult);
                                                                     /*
                                                                         * url = URL_LISTSHIPWEAPON + "STID=" + shiptypeid; url = url + "&encodedusername=" + encodedusername + "&encodeduserpass=" + encodeduserpass; String listweaponsresult =
                                                                         * HTTPGet.GetURL(url); Log.d(TAG, "list weapons - result:" + listweaponsresult);
                                                                         *
/
                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.ShipActivity.load");
                                                                     if (result.equals("") || weaponsresult.equals(""))// || listweaponsresult.equals(""))
                                                                     {
                                                                                     // website error most likely...
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ShipActivity.resultcode", false);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ShipActivity.failurereasoncode", NETWORK_GENERALERROR);
                                                                     }
                                                                     else
                                                                     {
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ShipActivity.resultcode", true);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ShipActivity.shipinfo", result);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ShipActivity.weaponinfo", weaponsresult);
                                                                                     // broadcastintent.putExtra("com.lloydm.geosword.activities.ShipActivity.availableweapons", listweaponsresult);

                                                                     }
                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                     sendBroadcast(broadcastintent);
                                                                     stopSelf(servid);

                                                     }
                                     }).start();

                     }
                     /*
                         * if (action.equals("com.lloydm.geosword.common.UploadService.shipdetails.update")) { // update ship info, choose new weapon, rebuild etc // get the shipinfo, list weapons, get current ship
                         * weapons final int shipid = intent.getIntExtra("com.lloydm.geosword.common.UploadService.shipid", 0); final int shiptypeid =
                         * intent.getIntExtra("com.lloydm.geosword.common.UploadService.shiptypeid", 0); final int weaponid = intent.getIntExtra("com.lloydm.geosword.common.UploadService.armamentid", 0);
                         *
                         * new Thread(new Runnable() {
                         *
                         * @Override public void run() { getuser(); if (notloggedin()) { // return a fail result Intent broadcastintent = new Intent("com.lloydm.geosword.activities.ShipActivity.update");
                         * broadcastintent.putExtra("com.lloydm.geosword.activities.ShipActivity.resultcode", false); if (weberror) { // most likely a connection failure of some sort...
                         * broadcastintent.putExtra("com.lloydm.geosword.activities.ShipActivity.authenticationerror", LOGIN_WEB_ERROR); } else { // appears that the user may not actually have a // login....or at
                         * least those credentials are // wrong.... broadcastintent.putExtra("com.lloydm.geosword.activities.ShipActivity.authenticationerror", LOGIN_NOT_FOUND); }
                         * broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid); sendBroadcast(broadcastintent);
                         *
                         * return; }
                         *
                         * String result = ""; if (weaponid != 0) { String url = URL_CHOOSESHIPWEAPON + "ASID=" + shipid + "&AID=" + weaponid; url = url + "&encodedusername=" + encodedusername + "&encodeduserpass=" +
                         * encodeduserpass; result = HTTPGet.GetURL(url); Log.d(TAG, "choose weap - result:" + result); } else { String url = URL_UPLOADSHIPINFO + "ID1=" + shipid + "&ID2=" + shiptypeid; url = url +
                         * "&encodedusername=" + encodedusername + "&encodeduserpass=" + encodeduserpass; result = HTTPGet.GetURL(url); Log.d(TAG, "upload ship - result:" + result); }
                         *
                         * Intent broadcastintent = new Intent("com.lloydm.geosword.activities.ShipActivity.update"); if (!result.equals("T")) { // website error most likely...
                         * broadcastintent.putExtra("com.lloydm.geosword.activities.ShipActivity.resultcode", false); broadcastintent.putExtra("com.lloydm.geosword.activities.ShipActivity.failurereasoncode",
                         * NETWORK_GENERALERROR)
; } else { broadcastintent.putExtra("com.lloydm.geosword.activities.ShipActivity.resultcode", true);
                         *
                         * } broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid); sendBroadcast(broadcastintent); } })
.start(); }
                         *
/
                     if (action.equals("com.lloydm.geosword.common.UploadService.modifyai.load"))
                     {
                                     // get the get slider values.....
                                     final int shipid = intent.getIntExtra("com.lloydm.geosword.common.UploadService.shipid", 0);
                                     final int servid = startId;
                                     new Thread(new Runnable()
                                     {
                                                     @Override
                                                     public void
run()
                                                     {
                                                                     getuser();
                                                                     if (notloggedin())
                                                                     {
                                                                                     // return a fail result
                                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.ModifyAIActivity.load");
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ModifyAIActivity.resultcode", false);
                                                                                     if (weberror)
                                                                                     {
                                                                                                     // most likely a connection failure of some sort...
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ModifyAIActivity.authenticationerror", LOGIN_WEB_ERROR);
                                                                                     }
                                                                                     else
                                                                                     {
                                                                                                     // appears that the user may not actually have a
                                                                                                     // login....or at least those credentials are
                                                                                                     // wrong....
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ModifyAIActivity.authenticationerror", LOGIN_NOT_FOUND);
                                                                                     }
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                     sendBroadcast(broadcastintent);
                                                                                     stopSelf(servid);
                                                                                     return;
                                                                     }
                                                                     String result = "";
                                                                     String url = URL_GETAISLIDERVALUES + "ID=" + shipid;
                                                                     url = url + "&encodedusername=" + encodedusername + "&encodeduserpass=" + encodeduserpass;
                                                                     result = HTTPGet.GetURL(url);
                                                                     Log.d(TAG, "get slider - result:" + result);

                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.ModifyAIActivity.load");
                                                                     if (result.equals(""))
                                                                     {
                                                                                     // website error most likely...
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ModifyAIActivity.resultcode", false);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ModifyAIActivity.failurereasoncode", NETWORK_GENERALERROR);
                                                                     }
                                                                     else
                                                                     {
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ModifyAIActivity.resultcode", true);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ModifyAIActivity.shipinfo", result);
                                                                     }
                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                     sendBroadcast(broadcastintent);
                                                                     stopSelf(servid);

                                                     }
                                     }).start();

                     }
                     // new
                     if (action.equals("com.lloydm.geosword.common.UploadService.map3d.load"))
                     {
                                     final int servid = startId;
                                     new Thread(new Runnable()
                                     {

                                                     @Override
                                                     public void
run()
                                                     {
                                                                     // getplanets.......100 planets....
                                                                     // all we do here is this.....
                                                                     String result = HTTPGet.GetURL(URL_GETWORLDCAMPAIGN);
                                                                     Log.d(TAG, "get skirmish results:" + result);
                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.Map3DActivity.load");
                                                                     if (result.equals(""))
                                                                     {
                                                                                     // website error most likely...
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.Map3DActivity.resultcode", false);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.Map3DActivity.failurereasoncode", NETWORK_GENERALERROR);
                                                                     }
                                                                     else
                                                                     {
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.Map3DActivity.resultcode", true);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.Map3DActivity.planets", result);
                                                                     }
                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                     sendBroadcast(broadcastintent);
                                                                     stopSelf(servid);
                                                     }
                                     }).start();

                     }
                     if (action.equals("com.lloydm.geosword.common.UploadService.map3d.update"))
                     {
                                     final int servid = startId;
                                     final int teamid = intent.getIntExtra("com.lloydm.geosword.common.UploadService.worldattack.teamid", 0);
                                     if (teamid != 0)
                                     {
                                                     new Thread(new Runnable()
                                                     {

                                                                     @Override
                                                                     public void
run()
                                                                     {
                                                                                     // String result = HTTPGet.GetURL(URL_LAUNCHWORLDATTACK+teamid);
                                                                                     String team1 = "0|1|7500|1|16|1.75|1.5|0.008|0.004|7500|675|0|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|21|-20|22|8|-1|1|0|100|0.7|4|3|3|0|0|1|0|0|40|0|0|0|0.02|15|800|1|-20|22|20|-1|1|0|100|0.7|4|3|3|0|0|1|0|0|40|0|0|0|0.02|15|800|1|-20|22|32|-1|1|0|100|0.7|4|3|3|0|0|1|0|0|40|0|0|0|0.02|15|800|1|-20|22|44|-1|1|0|100|0.7|4|3|3|0|0|1|0|0|40|0|0|0|0.02|15|800|1|-20|22|56|-1|1|0|100|0.7|4|3|3|0|0|1|0|0|40|0|0|0|0.02|15|800|1|20|22|8|1|1|0|100|0.7|4|3|3|0|0|1|0|0|40|0|0|0|0.02|15|800|1|20|22|20|1|1|0|100|0.7|4|3|3|0|0|1|0|0|40|0|0|0|0.02|15|800|1|20|22|32|1|1|0|100|0.7|4|3|3|0|0|1|0|0|40|0|0|0|0.02|15|800|1|20|22|44|1|1|0|100|0.7|4|3|3|0|0|1|0|0|40|0|0|0|0.02|15|800|1|20|22|56|1|1|0|100|0.7|4|3|3|0|0|1|0|0|40|0|0|0|0.02|15|800|1|-20|-2|8|-1|-1|0|100|0.7|4|3|3|0|0|1|0|0|40|0|0|0|0.02|15|800|1|-20|-2|20|-1|-1|0|100|0.7|4|3|3|0|0|1|0|0|40|0|0|0|0.02|15|800|1|-20|-2|32|-1|-1|0|100|0.7|4|3|3|0|0|1|0|0|40|0|0|0|0.02|15|800|1|-20|-2|44|-1|-1|0|100|0.7|4|3|3|0|0|1|0|0|40|0|0|0|0.02|15|800|1|-20|-2|56|-1|-1|0|100|0.7|4|3|3|0|0|1|0|0|40|0|0|0|0.02|15|800|1|20|-2|8|1|-1|0|100|0.7|4|3|3|0|0|1|0|0|40|0|0|0|0.02|15|800|1|20|-2|20|1|-1|0|100|0.7|4|3|3|0|0|1|0|0|40|0|0|0|0.02|15|800|1|20|-2|32|1|-1|0|100|0.7|4|3|3|0|0|1|0|0|40|0|0|0|0.02|15|800|1|20|-2|44|1|-1|0|100|0.7|4|3|3|0|0|1|0|0|40|0|0|0|0.02|15|800|1|20|-2|56|1|-1|0|100|0.7|4|3|3|0|0|1|0|0|40|0|0|0|0.02|15|800|1|-8|-12|114|0|0|1|100|0.8|2|0|0|0|0|5|0|0|1|1|0|0|0.02|15|800|2|350|1|0|ZZ:1|2|3000|1|12|2|1.5|0.01|0.005|3000|563|1|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|1|24|1.5|60|0|0|1|100|0.8|4|0|0|0|0|3|0|0|1|1|0|0|0.02|15|800|2|250|0|0|ZZ:2|2|3000|1|12|2|1.5|0.01|0.005|3000|563|1|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|1|24|1.5|60|0|0|1|100|0.8|4|0|0|0|0|3|0|0|1|1|0|0|0.02|15|800|2|250|0|0|ZZ:3|2|3000|1|12|2|1.5|0.01|0.005|3000|563|1|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|1|24|1.5|60|0|0|1|100|0.8|4|0|0|0|0|3|0|0|1|1|0|0|0.02|15|800|2|250|0|0|ZZ:4|3|150|1|2|3|2.5|0.103125|0.009375|150|375|2|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|4|-9|-2|0|0|0|1|100|0.8|9|7|7|0|0|4|4|4|40|0|0|0|0.02|15|800|1|9|-2|0|0|0|1|100|0.8|9|7|7|0|0|4|4|4|40|0|0|0|0.02|15|800|1|-8|-2|0|0|0|1|100|0.8|9|7|7|0|0|4|4|4|40|0|0|0|0.02|15|800|1|8|-2|0|0|0|1|100|0.8|9|7|7|0|0|4|4|4|40|0|0|0|0.02|15|800|1|30|0|0|ZZ:5|3|150|1|2|3|2.5|0.103125|0.009375|150|375|2|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|4|-9|-2|0|0|0|1|100|0.8|9|7|7|0|0|4|4|4|40|0|0|0|0.02|15|800|1|9|-2|0|0|0|1|100|0.8|9|7|7|0|0|4|4|4|40|0|0|0|0.02|15|800|1|-8|-2|0|0|0|1|100|0.8|9|7|7|0|0|4|4|4|40|0|0|0|0.02|15|800|1|8|-2|0|0|0|1|100|0.8|9|7|7|0|0|4|4|4|40|0|0|0|0.02|15|800|1|30|0|0|ZZ:6|3|150|1|2|3|2.5|0.103125|0.009375|150|375|2|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|4|-9|-2|0|0|0|1|100|0.8|9|7|7|0|0|4|4|4|40|0|0|0|0.02|15|800|1|9|-2|0|0|0|1|100|0.8|9|7|7|0|0|4|4|4|40|0|0|0|0.02|15|800|1|-8|-2|0|0|0|1|100|0.8|9|7|7|0|0|4|4|4|40|0|0|0|0.02|15|800|1|8|-2|0|0|0|1|100|0.8|9|7|7|0|0|4|4|4|40|0|0|0|0.02|15|800|1|30|0|0|ZZ:7|3|150|1|2|3|2.5|0.103125|0.009375|150|375|2|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|4|-9|-2|0|0|0|1|100|0.8|9|7|7|0|0|4|4|4|40|0|0|0|0.02|15|800|1|9|-2|0|0|0|1|100|0.8|9|7|7|0|0|4|4|4|40|0|0|0|0.02|15|800|1|-8|-2|0|0|0|1|100|0.8|9|7|7|0|0|4|4|4|40|0|0|0|0.02|15|800|1|8|-2|0|0|0|1|100|0.8|9|7|7|0|0|4|4|4|40|0|0|0|0.02|15|800|1|30|0|0|ZZ:8|4|50|1|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|7.2|-1.7|7.5|0|0|1|100|0.8|3|9|9|0|0|5|1|1|38|0|0|0|0.02|15|800|1|-7.2|-1.7|7.5|0|0|1|100|0.8|3|9|9|0|0|5|1|1|38|0|0|0|0.02|15|800|1|20|0|0|ZZ:9|4|50|1|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|7.2|-1.7|7.5|0|0|1|100|0.8|3|9|9|0|0|5|1|1|38|0|0|0|0.02|15|800|1|-7.2|-1.7|7.5|0|0|1|100|0.8|3|9|9|0|0|5|1|1|38|0|0|0|0.02|15|800|1|20|0|0|ZZ:10|4|50|1|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|7.2|-1.7|7.5|0|0|1|100|0.8|3|9|9|0|0|5|1|1|38|0|0|0|0.02|15|800|1|-7.2|-1.7|7.5|0|0|1|100|0.8|3|9|9|0|0|5|1|1|38|0|0|0|0.02|15|800|1|20|0|0|ZZ:11|4|50|1|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|7.2|-1.7|7.5|0|0|1|100|0.8|3|9|9|0|0|5|1|1|38|0|0|0|0.02|15|800|1|-7.2|-1.7|7.5|0|0|1|100|0.8|3|9|9|0|0|5|1|1|38|0|0|0|0.02|15|800|1|20|0|0|ZZ:12|4|50|1|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|7.2|-1.7|7.5|0|0|1|100|0.8|3|9|9|0|0|5|1|1|38|0|0|0|0.02|15|800|1|-7.2|-1.7|7.5|0|0|1|100|0.8|3|9|9|0|0|5|1|1|38|0|0|0|0.02|15|800|1|20|0|0|ZZ:13|4|50|1|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|7.2|-1.7|7.5|0|0|1|100|0.8|3|9|9|0|0|5|1|1|38|0|0|0|0.02|15|800|1|-7.2|-1.7|7.5|0|0|1|100|0.8|3|9|9|0|0|5|1|1|38|0|0|0|0.02|15|800|1|20|0|0|ZZ:14|4|50|1|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|7.2|-1.7|7.5|0|0|1|100|0.8|3|9|9|0|0|5|1|1|38|0|0|0|0.02|15|800|1|-7.2|-1.7|7.5|0|0|1|100|0.8|3|9|9|0|0|5|1|1|38|0|0|0|0.02|15|800|1|20|0|0|ZZ:15|4|50|1|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|7.2|-1.7|7.5|0|0|1|100|0.8|3|9|9|0|0|5|1|1|38|0|0|0|0.02|15|800|1|-7.2|-1.7|7.5|0|0|1|100|0.8|3|9|9|0|0|5|1|1|38|0|0|0|0.02|15|800|1|20|0|0|ZZ:";
                                                                                     String team2 = "0|1|7500|2|16|1.75|1.5|0.008|0.004|7500|675|0|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|1|0|-3.2|90|0|0|1|100|0.75|10|0|0|0|0|3|0|0|1|1|0|0|0.02|15|800|2|350|1|0|ZZ:1|2|3000|2|12|2|1.5|0.01|0.005|3000|563|1|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|-10|8|14|0|0|1|100|0.5|5|5|5|100|100|2|0|0|20|0|1|1|0.02|15|800|3|10|8|14|0|0|1|100|0.5|5|5|5|100|100|2|0|0|20|0|1|1|0.02|15|800|3|4|-1|33|0|0|1|100|0.8|1|0|0|0|0|4|0|0|1|1|0|0|0.02|15|800|2|-16|-2|24|0|0|1|100|0.8|4|7|7|0|0|3|0|0|20|0|0|0|0.02|15|800|1|16|-2|24|0|0|1|100|0.8|4|7|7|0|0|3|0|0|20|0|0|0|0.02|15|800|1|250|0|0|ZZ:2|2|3000|2|12|2|1.5|0.01|0.005|3000|563|1|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|-10|8|14|0|0|1|100|0.5|5|5|5|100|100|2|0|0|20|0|1|1|0.02|15|800|3|10|8|14|0|0|1|100|0.5|5|5|5|100|100|2|0|0|20|0|1|1|0.02|15|800|3|4|-1|33|0|0|1|100|0.8|1|0|0|0|0|4|0|0|1|1|0|0|0.02|15|800|2|-16|-2|24|0|0|1|100|0.8|4|7|7|0|0|3|0|0|20|0|0|0|0.02|15|800|1|16|-2|24|0|0|1|100|0.8|4|7|7|0|0|3|0|0|20|0|0|0|0.02|15|800|1|250|0|0|ZZ:3|2|3000|2|12|2|1.5|0.01|0.005|3000|563|1|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|-10|8|14|0|0|1|100|0.5|5|5|5|100|100|2|0|0|20|0|1|1|0.02|15|800|3|10|8|14|0|0|1|100|0.5|5|5|5|100|100|2|0|0|20|0|1|1|0.02|15|800|3|4|-1|33|0|0|1|100|0.8|1|0|0|0|0|4|0|0|1|1|0|0|0.02|15|800|2|-16|-2|24|0|0|1|100|0.8|4|7|7|0|0|3|0|0|20|0|0|0|0.02|15|800|1|16|-2|24|0|0|1|100|0.8|4|7|7|0|0|3|0|0|20|0|0|0|0.02|15|800|1|250|0|0|ZZ:4|3|150|2|2|3|2.5|0.103125|0.009375|150|375|2|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|-5|-1|4.5|0|0|1|100|0.8|12|5|5|0|0|12|8|8|44|0|0|0|0.02|15|800|1|5|-1|4.5|0|0|1|100|0.8|12|5|5|0|0|12|8|8|44|0|0|0|0.02|15|800|1|30|0|0|ZZ:5|3|150|2|2|3|2.5|0.103125|0.009375|150|375|2|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|-5|-1|4.5|0|0|1|100|0.8|12|5|5|0|0|12|8|8|44|0|0|0|0.02|15|800|1|5|-1|4.5|0|0|1|100|0.8|12|5|5|0|0|12|8|8|44|0|0|0|0.02|15|800|1|30|0|0|ZZ:6|3|150|2|2|3|2.5|0.103125|0.009375|150|375|2|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|-5|-1|4.5|0|0|1|100|0.8|12|5|5|0|0|12|8|8|44|0|0|0|0.02|15|800|1|5|-1|4.5|0|0|1|100|0.8|12|5|5|0|0|12|8|8|44|0|0|0|0.02|15|800|1|30|0|0|ZZ:7|3|150|2|2|3|2.5|0.103125|0.009375|150|375|2|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|-5|-1|4.5|0|0|1|100|0.8|12|5|5|0|0|12|8|8|44|0|0|0|0.02|15|800|1|5|-1|4.5|0|0|1|100|0.8|12|5|5|0|0|12|8|8|44|0|0|0|0.02|15|800|1|30|0|0|ZZ:8|4|50|2|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|-3.75|-1|6.5|0|0|1|100|0.8|3|7|7|0|0|5|1|1|38|0|0|0|0.02|15|800|1|3.75|-1|6.5|0|0|1|100|0.8|3|7|7|0|0|5|1|1|38|0|0|0|0.02|15|800|1|20|0|0|ZZ:9|4|50|2|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|-3.75|-1|6.5|0|0|1|100|0.8|3|7|7|0|0|5|1|1|38|0|0|0|0.02|15|800|1|3.75|-1|6.5|0|0|1|100|0.8|3|7|7|0|0|5|1|1|38|0|0|0|0.02|15|800|1|20|0|0|ZZ:10|4|50|2|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|-3.75|-1|6.5|0|0|1|100|0.8|3|7|7|0|0|5|1|1|38|0|0|0|0.02|15|800|1|3.75|-1|6.5|0|0|1|100|0.8|3|7|7|0|0|5|1|1|38|0|0|0|0.02|15|800|1|20|0|0|ZZ:11|4|50|2|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|-3.75|-1|6.5|0|0|1|100|0.8|3|7|7|0|0|5|1|1|38|0|0|0|0.02|15|800|1|3.75|-1|6.5|0|0|1|100|0.8|3|7|7|0|0|5|1|1|38|0|0|0|0.02|15|800|1|20|0|0|ZZ:12|4|50|2|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|-3.75|-1|6.5|0|0|1|100|0.8|3|7|7|0|0|5|1|1|38|0|0|0|0.02|15|800|1|3.75|-1|6.5|0|0|1|100|0.8|3|7|7|0|0|5|1|1|38|0|0|0|0.02|15|800|1|20|0|0|ZZ:13|4|50|2|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|-3.75|-1|6.5|0|0|1|100|0.8|3|7|7|0|0|5|1|1|38|0|0|0|0.02|15|800|1|3.75|-1|6.5|0|0|1|100|0.8|3|7|7|0|0|5|1|1|38|0|0|0|0.02|15|800|1|20|0|0|ZZ:14|4|50|2|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|-3.75|-1|6.5|0|0|1|100|0.8|3|7|7|0|0|5|1|1|38|0|0|0|0.02|15|800|1|3.75|-1|6.5|0|0|1|100|0.8|3|7|7|0|0|5|1|1|38|0|0|0|0.02|15|800|1|20|0|0|ZZ:15|4|50|2|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|-3.75|-1|6.5|0|0|1|100|0.8|3|7|7|0|0|5|1|1|38|0|0|0|0.02|15|800|1|3.75|-1|6.5|0|0|1|100|0.8|3|7|7|0|0|5|1|1|38|0|0|0|0.02|15|800|1|20|0|0|ZZ:";
                                                                                     String team3 = "0|1|7500|3|16|1.75|1.5|0.008|0.004|7500|675|0|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|7|-28|-6|60|0|0|1|100|0.75|7|0|0|20|20|5|0|0|1|1|0|0|0.02|15|800|2|24|-8|20|0|0|1|100|0.75|22|22|22|0|0|15|0|0|20|0|0|0|0.02|15|800|4|-24|-8|20|0|0|1|100|0.75|22|22|22|0|0|15|0|0|20|0|0|0|0.02|15|800|4|44|-2|0|0|0|1|100|0.75|55|60|60|0|0|15|0|0|60|0|0|0|0.02|15|800|4|-44|-2|0|0|0|1|100|0.75|55|60|60|0|0|15|0|0|60|0|0|0|0.02|15|800|4|44|-6|0|0|0|1|100|0.75|55|60|60|0|0|15|0|0|60|0|0|0|0.02|15|800|4|-44|-6|0|0|0|1|100|0.75|55|60|60|0|0|15|0|0|60|0|0|0|0.02|15|800|4|350|1|0|ZZ:1|2|3000|3|12|2|1.5|0.01|0.005|3000|563|1|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|7|24|0|45|0|0|1|100|0.8|45|60|60|0|0|15|0|0|60|0|0|0|0.02|15|800|4|-24|0|45|0|0|1|100|0.8|45|60|60|0|0|15|0|0|60|0|0|0|0.02|15|800|4|24|-7.5|48|0|0|1|100|0.8|45|60|60|0|0|15|0|0|60|0|0|0|0.02|15|800|4|-24|-7.5|48|0|0|1|100|0.8|45|60|60|0|0|15|0|0|60|0|0|0|0.02|15|800|4|10|-15|70|0|0|1|100|0.8|18|22|22|0|0|15|0|0|20|0|0|0|0.02|15|800|4|-10|-15|70|0|0|1|100|0.8|18|22|22|0|0|15|0|0|20|0|0|0|0.02|15|800|4|-47|1|-14|0|0|1|100|0.8|7|0|0|20|20|5|0|0|1|1|0|0|0.02|15|800|2|250|0|0|ZZ:2|2|3000|3|12|2|1.5|0.01|0.005|3000|563|1|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|7|24|0|45|0|0|1|100|0.8|45|60|60|0|0|15|0|0|60|0|0|0|0.02|15|800|4|-24|0|45|0|0|1|100|0.8|45|60|60|0|0|15|0|0|60|0|0|0|0.02|15|800|4|24|-7.5|48|0|0|1|100|0.8|45|60|60|0|0|15|0|0|60|0|0|0|0.02|15|800|4|-24|-7.5|48|0|0|1|100|0.8|45|60|60|0|0|15|0|0|60|0|0|0|0.02|15|800|4|10|-15|70|0|0|1|100|0.8|18|22|22|0|0|15|0|0|20|0|0|0|0.02|15|800|4|-10|-15|70|0|0|1|100|0.8|18|22|22|0|0|15|0|0|20|0|0|0|0.02|15|800|4|-47|1|-14|0|0|1|100|0.8|7|0|0|20|20|5|0|0|1|1|0|0|0.02|15|800|2|250|0|0|ZZ:3|2|3000|3|12|2|1.5|0.01|0.005|3000|563|1|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|7|24|0|45|0|0|1|100|0.8|45|60|60|0|0|15|0|0|60|0|0|0|0.02|15|800|4|-24|0|45|0|0|1|100|0.8|45|60|60|0|0|15|0|0|60|0|0|0|0.02|15|800|4|24|-7.5|48|0|0|1|100|0.8|45|60|60|0|0|15|0|0|60|0|0|0|0.02|15|800|4|-24|-7.5|48|0|0|1|100|0.8|45|60|60|0|0|15|0|0|60|0|0|0|0.02|15|800|4|10|-15|70|0|0|1|100|0.8|18|22|22|0|0|15|0|0|20|0|0|0|0.02|15|800|4|-10|-15|70|0|0|1|100|0.8|18|22|22|0|0|15|0|0|20|0|0|0|0.02|15|800|4|-47|1|-14|0|0|1|100|0.8|7|0|0|20|20|5|0|0|1|1|0|0|0.02|15|800|2|250|0|0|ZZ:4|3|150|3|2|3|2.5|0.103125|0.009375|150|375|2|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|3|2|0|1.25|0|0|1|100|0.8|13|7|7|0|0|10|0|0|38|0|0|0|0.02|15|800|4|-2|0|1.25|0|0|1|100|0.8|13|7|7|0|0|10|0|0|38|0|0|0|0.02|15|800|4|4.5|-2|1.25|0|0|1|100|0.5|48|23|23|8|8|5|10|10|80|0|1|1|0.02|15|800|3|30|0|0|ZZ:5|3|150|3|2|3|2.5|0.103125|0.009375|150|375|2|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|3|2|0|1.25|0|0|1|100|0.8|13|7|7|0|0|10|0|0|38|0|0|0|0.02|15|800|4|-2|0|1.25|0|0|1|100|0.8|13|7|7|0|0|10|0|0|38|0|0|0|0.02|15|800|4|4.5|-2|1.25|0|0|1|100|0.5|48|23|23|8|8|5|10|10|80|0|1|1|0.02|15|800|3|30|0|0|ZZ:6|3|150|3|2|3|2.5|0.103125|0.009375|150|375|2|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|3|2|0|1.25|0|0|1|100|0.8|13|7|7|0|0|10|0|0|38|0|0|0|0.02|15|800|4|-2|0|1.25|0|0|1|100|0.8|13|7|7|0|0|10|0|0|38|0|0|0|0.02|15|800|4|4.5|-2|1.25|0|0|1|100|0.5|48|23|23|8|8|5|10|10|80|0|1|1|0.02|15|800|3|30|0|0|ZZ:7|3|150|3|2|3|2.5|0.103125|0.009375|150|375|2|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|3|2|0|1.25|0|0|1|100|0.8|13|7|7|0|0|10|0|0|38|0|0|0|0.02|15|800|4|-2|0|1.25|0|0|1|100|0.8|13|7|7|0|0|10|0|0|38|0|0|0|0.02|15|800|4|4.5|-2|1.25|0|0|1|100|0.5|48|23|23|8|8|5|10|10|80|0|1|1|0.02|15|800|3|30|0|0|ZZ:8|4|50|3|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|-5|-2.75|0|0|0|1|100|0.8|13|7|7|0|0|10|0|0|38|0|0|0|0.02|15|800|4|5|-2.75|0|0|0|1|100|0.8|13|7|7|0|0|10|0|0|38|0|0|0|0.02|15|800|4|20|0|0|ZZ:9|4|50|3|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|-5|-2.75|0|0|0|1|100|0.8|13|7|7|0|0|10|0|0|38|0|0|0|0.02|15|800|4|5|-2.75|0|0|0|1|100|0.8|13|7|7|0|0|10|0|0|38|0|0|0|0.02|15|800|4|20|0|0|ZZ:10|4|50|3|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|-5|-2.75|0|0|0|1|100|0.8|13|7|7|0|0|10|0|0|38|0|0|0|0.02|15|800|4|5|-2.75|0|0|0|1|100|0.8|13|7|7|0|0|10|0|0|38|0|0|0|0.02|15|800|4|20|0|0|ZZ:11|4|50|3|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|-5|-2.75|0|0|0|1|100|0.8|13|7|7|0|0|10|0|0|38|0|0|0|0.02|15|800|4|5|-2.75|0|0|0|1|100|0.8|13|7|7|0|0|10|0|0|38|0|0|0|0.02|15|800|4|20|0|0|ZZ:12|4|50|3|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|-5|-2.75|0|0|0|1|100|0.8|13|7|7|0|0|10|0|0|38|0|0|0|0.02|15|800|4|5|-2.75|0|0|0|1|100|0.8|13|7|7|0|0|10|0|0|38|0|0|0|0.02|15|800|4|20|0|0|ZZ:13|4|50|3|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|-5|-2.75|0|0|0|1|100|0.8|13|7|7|0|0|10|0|0|38|0|0|0|0.02|15|800|4|5|-2.75|0|0|0|1|100|0.8|13|7|7|0|0|10|0|0|38|0|0|0|0.02|15|800|4|20|0|0|ZZ:14|4|50|3|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|-5|-2.75|0|0|0|1|100|0.8|13|7|7|0|0|10|0|0|38|0|0|0|0.02|15|800|4|5|-2.75|0|0|0|1|100|0.8|13|7|7|0|0|10|0|0|38|0|0|0|0.02|15|800|4|20|0|0|ZZ:15|4|50|3|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|-5|-2.75|0|0|0|1|100|0.8|13|7|7|0|0|10|0|0|38|0|0|0|0.02|15|800|4|5|-2.75|0|0|0|1|100|0.8|13|7|7|0|0|10|0|0|38|0|0|0|0.02|15|800|4|20|0|0|ZZ:";
                                                                                     String team4 = "0|1|7500|4|16|1.75|1.5|0.008|0.004|7500|675|0|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|7|4|-10|21|0|0|1|100|0.65|9|2|2|100|100|1|0|0|50|0|0|0|0.02|15|800|1|-4|-10|21|0|0|1|100|0.65|9|2|2|100|100|1|0|0|50|0|0|0|0.02|15|800|1|20|-12|21|0|0|1|100|0.65|9|2|2|100|100|1|0|0|50|0|0|0|0.02|15|800|1|-20|-12|21|0|0|1|100|0.65|9|2|2|100|100|1|0|0|50|0|0|0|0.02|15|800|1|15|7.5|16|0|0|1|100|0.65|9|2|2|100|100|1|0|0|50|0|0|0|0.02|15|800|1|-15|7.5|16|0|0|1|100|0.65|9|2|2|100|100|1|0|0|50|0|0|0|0.02|15|800|1|-10|-3|80|0|0|1|100|0.8|3|1|1|0|0|7|0|0|1|0|0|0|0.02|15|800|6|350|1|0|ZZ:1|2|3000|4|12|2|1.5|0.01|0.005|3000|563|1|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|3|16|15|52|0|0|1|100|0.55|5|2|2|75|75|1|0|0|50|0|0|0|0.02|15|800|1|-16|15|52|0|0|1|100|0.55|5|2|2|75|75|1|0|0|50|0|0|0|0.02|15|800|1|-3|4|80|0|0|1|100|0.8|2|1|1|0|0|5|0|0|1|0|0|0|0.02|15|800|6|250|0|0|ZZ:2|2|3000|4|12|2|1.5|0.01|0.005|3000|563|1|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|3|16|15|52|0|0|1|100|0.55|5|2|2|75|75|1|0|0|50|0|0|0|0.02|15|800|1|-16|15|52|0|0|1|100|0.55|5|2|2|75|75|1|0|0|50|0|0|0|0.02|15|800|1|-3|4|80|0|0|1|100|0.8|2|1|1|0|0|5|0|0|1|0|0|0|0.02|15|800|6|250|0|0|ZZ:3|2|3000|4|12|2|1.5|0.01|0.005|3000|563|1|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|3|16|15|52|0|0|1|100|0.55|5|2|2|75|75|1|0|0|50|0|0|0|0.02|15|800|1|-16|15|52|0|0|1|100|0.55|5|2|2|75|75|1|0|0|50|0|0|0|0.02|15|800|1|-3|4|80|0|0|1|100|0.8|2|1|1|0|0|5|0|0|1|0|0|0|0.02|15|800|6|250|0|0|ZZ:4|3|150|4|2|3|2.5|0.103125|0.009375|150|375|2|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|6|-4.5|3.75|1.5|0|0|1|100|0.65|5|13|13|30|30|0|0|0|50|0|1|1|0.02|15|800|3|4.5|3.75|1.5|0|0|1|100|0.65|5|13|13|30|30|0|0|0|50|0|1|1|0.02|15|800|3|-9|-2|3.5|0|0|1|100|0.8|6|8|8|0|0|9|1|1|38|0|0|0|0.02|15|800|1|9|-2|3.5|0|0|1|100|0.8|6|8|8|0|0|9|1|1|38|0|0|0|0.02|15|800|1|-5|-2|16|0|0|1|100|0.8|6|8|8|0|0|9|1|1|38|0|0|0|0.02|15|800|1|5|-2|16|0|0|1|100|0.8|6|8|8|0|0|9|1|1|38|0|0|0|0.02|15|800|1|30|0|0|ZZ:5|3|150|4|2|3|2.5|0.103125|0.009375|150|375|2|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|6|-4.5|3.75|1.5|0|0|1|100|0.65|5|13|13|30|30|0|0|0|50|0|1|1|0.02|15|800|3|4.5|3.75|1.5|0|0|1|100|0.65|5|13|13|30|30|0|0|0|50|0|1|1|0.02|15|800|3|-9|-2|3.5|0|0|1|100|0.8|6|8|8|0|0|9|1|1|38|0|0|0|0.02|15|800|1|9|-2|3.5|0|0|1|100|0.8|6|8|8|0|0|9|1|1|38|0|0|0|0.02|15|800|1|-5|-2|16|0|0|1|100|0.8|6|8|8|0|0|9|1|1|38|0|0|0|0.02|15|800|1|5|-2|16|0|0|1|100|0.8|6|8|8|0|0|9|1|1|38|0|0|0|0.02|15|800|1|30|0|0|ZZ:6|3|150|4|2|3|2.5|0.103125|0.009375|150|375|2|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|6|-4.5|3.75|1.5|0|0|1|100|0.65|5|13|13|30|30|0|0|0|50|0|1|1|0.02|15|800|3|4.5|3.75|1.5|0|0|1|100|0.65|5|13|13|30|30|0|0|0|50|0|1|1|0.02|15|800|3|-9|-2|3.5|0|0|1|100|0.8|6|8|8|0|0|9|1|1|38|0|0|0|0.02|15|800|1|9|-2|3.5|0|0|1|100|0.8|6|8|8|0|0|9|1|1|38|0|0|0|0.02|15|800|1|-5|-2|16|0|0|1|100|0.8|6|8|8|0|0|9|1|1|38|0|0|0|0.02|15|800|1|5|-2|16|0|0|1|100|0.8|6|8|8|0|0|9|1|1|38|0|0|0|0.02|15|800|1|30|0|0|ZZ:7|3|150|4|2|3|2.5|0.103125|0.009375|150|375|2|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|6|-4.5|3.75|1.5|0|0|1|100|0.65|5|13|13|30|30|0|0|0|50|0|1|1|0.02|15|800|3|4.5|3.75|1.5|0|0|1|100|0.65|5|13|13|30|30|0|0|0|50|0|1|1|0.02|15|800|3|-9|-2|3.5|0|0|1|100|0.8|6|8|8|0|0|9|1|1|38|0|0|0|0.02|15|800|1|9|-2|3.5|0|0|1|100|0.8|6|8|8|0|0|9|1|1|38|0|0|0|0.02|15|800|1|-5|-2|16|0|0|1|100|0.8|6|8|8|0|0|9|1|1|38|0|0|0|0.02|15|800|1|5|-2|16|0|0|1|100|0.8|6|8|8|0|0|9|1|1|38|0|0|0|0.02|15|800|1|30|0|0|ZZ:8|4|50|4|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|6|4.5|3|-2|0|0|1|100|0.65|3|13|13|30|30|0|0|0|50|0|1|1|0.02|15|800|3|-4.5|3|-2|0|0|1|100|0.65|3|13|13|30|30|0|0|0|50|0|1|1|0.02|15|800|3|9|0|6|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|-9|0|6|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|2|0.5|12|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|-2|0.5|12|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|20|0|0|ZZ:9|4|50|4|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|6|4.5|3|-2|0|0|1|100|0.65|3|13|13|30|30|0|0|0|50|0|1|1|0.02|15|800|3|-4.5|3|-2|0|0|1|100|0.65|3|13|13|30|30|0|0|0|50|0|1|1|0.02|15|800|3|9|0|6|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|-9|0|6|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|2|0.5|12|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|-2|0.5|12|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|20|0|0|ZZ:10|4|50|4|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|6|4.5|3|-2|0|0|1|100|0.65|3|13|13|30|30|0|0|0|50|0|1|1|0.02|15|800|3|-4.5|3|-2|0|0|1|100|0.65|3|13|13|30|30|0|0|0|50|0|1|1|0.02|15|800|3|9|0|6|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|-9|0|6|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|2|0.5|12|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|-2|0.5|12|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|20|0|0|ZZ:11|4|50|4|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|6|4.5|3|-2|0|0|1|100|0.65|3|13|13|30|30|0|0|0|50|0|1|1|0.02|15|800|3|-4.5|3|-2|0|0|1|100|0.65|3|13|13|30|30|0|0|0|50|0|1|1|0.02|15|800|3|9|0|6|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|-9|0|6|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|2|0.5|12|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|-2|0.5|12|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|20|0|0|ZZ:12|4|50|4|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|6|4.5|3|-2|0|0|1|100|0.65|3|13|13|30|30|0|0|0|50|0|1|1|0.02|15|800|3|-4.5|3|-2|0|0|1|100|0.65|3|13|13|30|30|0|0|0|50|0|1|1|0.02|15|800|3|9|0|6|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|-9|0|6|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|2|0.5|12|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|-2|0.5|12|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|20|0|0|ZZ:13|4|50|4|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|6|4.5|3|-2|0|0|1|100|0.65|3|13|13|30|30|0|0|0|50|0|1|1|0.02|15|800|3|-4.5|3|-2|0|0|1|100|0.65|3|13|13|30|30|0|0|0|50|0|1|1|0.02|15|800|3|9|0|6|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|-9|0|6|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|2|0.5|12|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|-2|0.5|12|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|20|0|0|ZZ:14|4|50|4|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|6|4.5|3|-2|0|0|1|100|0.65|3|13|13|30|30|0|0|0|50|0|1|1|0.02|15|800|3|-4.5|3|-2|0|0|1|100|0.65|3|13|13|30|30|0|0|0|50|0|1|1|0.02|15|800|3|9|0|6|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|-9|0|6|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|2|0.5|12|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|-2|0.5|12|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|20|0|0|ZZ:15|4|50|4|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|6|4.5|3|-2|0|0|1|100|0.65|3|13|13|30|30|0|0|0|50|0|1|1|0.02|15|800|3|-4.5|3|-2|0|0|1|100|0.65|3|13|13|30|30|0|0|0|50|0|1|1|0.02|15|800|3|9|0|6|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|-9|0|6|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|2|0.5|12|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|-2|0.5|12|0|0|1|100|0.8|4|6|6|0|0|10|1|1|38|0|0|0|0.02|15|800|1|20|0|0|ZZ:";
                                                                                     String team5 = "0|1|7500|5|16|1.75|1.5|0.008|0.004|7500|675|0|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|6|16|20|-8|0|0|1|100|0.73|8|4|4|0|0|4|2|2|37|0|0|0|0.02|15|800|6|-16|20|-8|0|0|1|100|0.73|8|4|4|0|0|4|2|2|37|0|0|0|0.02|15|800|6|46|-5|18|0|0|1|100|0.73|6|0|0|0|0|1|0|0|1|1|0|0|0.02|15|800|2|-46|-5|18|0|0|1|100|0.73|8|4|4|0|0|4|2|2|37|0|0|0|0.02|15|800|6|52|-5|0|0|0|1|100|0.73|8|4|4|0|0|4|2|2|37|0|0|0|0.02|15|800|6|-52|-5|0|0|0|1|100|0.73|8|4|4|0|0|4|2|2|37|0|0|0|0.02|15|800|6|350|1|0|ZZ:1|2|3000|5|12|2|1.5|0.01|0.005|3000|563|1|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|4|43|2|20|0|0|1|100|0.8|13|7|7|0|0|3|1|1|47|0|0|0|0.02|15|800|6|-43|2|20|0|0|1|100|0.8|13|7|7|0|0|3|1|1|47|0|0|0|0.02|15|800|6|17.5|-3|46|0|0|1|100|0.8|13|7|7|0|0|3|1|1|47|0|0|0|0.02|15|800|6|-17.5|-3|46|0|0|1|100|0.8|13|7|7|0|0|3|1|1|47|0|0|0|0.02|15|800|6|250|0|0|ZZ:2|2|3000|5|12|2|1.5|0.01|0.005|3000|563|1|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|4|43|2|20|0|0|1|100|0.8|13|7|7|0|0|3|1|1|47|0|0|0|0.02|15|800|6|-43|2|20|0|0|1|100|0.8|13|7|7|0|0|3|1|1|47|0|0|0|0.02|15|800|6|17.5|-3|46|0|0|1|100|0.8|13|7|7|0|0|3|1|1|47|0|0|0|0.02|15|800|6|-17.5|-3|46|0|0|1|100|0.8|13|7|7|0|0|3|1|1|47|0|0|0|0.02|15|800|6|250|0|0|ZZ:3|2|3000|5|12|2|1.5|0.01|0.005|3000|563|1|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|4|43|2|20|0|0|1|100|0.8|13|7|7|0|0|3|1|1|47|0|0|0|0.02|15|800|6|-43|2|20|0|0|1|100|0.8|13|7|7|0|0|3|1|1|47|0|0|0|0.02|15|800|6|17.5|-3|46|0|0|1|100|0.8|13|7|7|0|0|3|1|1|47|0|0|0|0.02|15|800|6|-17.5|-3|46|0|0|1|100|0.8|13|7|7|0|0|3|1|1|47|0|0|0|0.02|15|800|6|250|0|0|ZZ:4|3|150|5|2|3|2.5|0.103125|0.009375|150|375|2|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|6|4|3|-6|0|0|-1|100|0.5|3|8|8|15|15|3|1|1|38|0|0|0|0.02|15|800|1|-4|3|-6|0|0|-1|100|0.5|3|8|8|15|15|3|1|1|38|0|0|0|0.02|15|800|1|3|3|-8|0|0|-1|100|0.5|3|8|8|15|15|3|1|1|38|0|0|0|0.02|15|800|1|-3|3|-8|0|0|-1|100|0.5|3|8|8|15|15|3|1|1|38|0|0|0|0.02|15|800|1|1|-1|8|0|0|1|100|0.8|5|8|8|0|0|1|0|0|38|0|0|0|0.02|15|800|6|-1|-1|8|0|0|1|100|0.8|5|8|8|0|0|1|0|0|38|0|0|0|0.02|15|800|6|30|0|0|ZZ:5|3|150|5|2|3|2.5|0.103125|0.009375|150|375|2|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|6|4|3|-6|0|0|-1|100|0.5|3|8|8|15|15|3|1|1|38|0|0|0|0.02|15|800|1|-4|3|-6|0|0|-1|100|0.5|3|8|8|15|15|3|1|1|38|0|0|0|0.02|15|800|1|3|3|-8|0|0|-1|100|0.5|3|8|8|15|15|3|1|1|38|0|0|0|0.02|15|800|1|-3|3|-8|0|0|-1|100|0.5|3|8|8|15|15|3|1|1|38|0|0|0|0.02|15|800|1|1|-1|8|0|0|1|100|0.8|5|8|8|0|0|1|0|0|38|0|0|0|0.02|15|800|6|-1|-1|8|0|0|1|100|0.8|5|8|8|0|0|1|0|0|38|0|0|0|0.02|15|800|6|30|0|0|ZZ:6|3|150|5|2|3|2.5|0.103125|0.009375|150|375|2|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|6|4|3|-6|0|0|-1|100|0.5|3|8|8|15|15|3|1|1|38|0|0|0|0.02|15|800|1|-4|3|-6|0|0|-1|100|0.5|3|8|8|15|15|3|1|1|38|0|0|0|0.02|15|800|1|3|3|-8|0|0|-1|100|0.5|3|8|8|15|15|3|1|1|38|0|0|0|0.02|15|800|1|-3|3|-8|0|0|-1|100|0.5|3|8|8|15|15|3|1|1|38|0|0|0|0.02|15|800|1|1|-1|8|0|0|1|100|0.8|5|8|8|0|0|1|0|0|38|0|0|0|0.02|15|800|6|-1|-1|8|0|0|1|100|0.8|5|8|8|0|0|1|0|0|38|0|0|0|0.02|15|800|6|30|0|0|ZZ:7|3|150|5|2|3|2.5|0.103125|0.009375|150|375|2|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|6|4|3|-6|0|0|-1|100|0.5|3|8|8|15|15|3|1|1|38|0|0|0|0.02|15|800|1|-4|3|-6|0|0|-1|100|0.5|3|8|8|15|15|3|1|1|38|0|0|0|0.02|15|800|1|3|3|-8|0|0|-1|100|0.5|3|8|8|15|15|3|1|1|38|0|0|0|0.02|15|800|1|-3|3|-8|0|0|-1|100|0.5|3|8|8|15|15|3|1|1|38|0|0|0|0.02|15|800|1|1|-1|8|0|0|1|100|0.8|5|8|8|0|0|1|0|0|38|0|0|0|0.02|15|800|6|-1|-1|8|0|0|1|100|0.8|5|8|8|0|0|1|0|0|38|0|0|0|0.02|15|800|6|30|0|0|ZZ:8|4|50|5|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|1|-1|8|0|0|1|100|0.8|2|8|8|0|0|1|0|0|38|0|0|0|0.02|15|800|6|-1|-1|8|0|0|1|100|0.8|2|8|8|0|0|1|0|0|38|0|0|0|0.02|15|800|6|20|0|0|ZZ:9|4|50|5|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|1|-1|8|0|0|1|100|0.8|2|8|8|0|0|1|0|0|38|0|0|0|0.02|15|800|6|-1|-1|8|0|0|1|100|0.8|2|8|8|0|0|1|0|0|38|0|0|0|0.02|15|800|6|20|0|0|ZZ:10|4|50|5|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|1|-1|8|0|0|1|100|0.8|2|8|8|0|0|1|0|0|38|0|0|0|0.02|15|800|6|-1|-1|8|0|0|1|100|0.8|2|8|8|0|0|1|0|0|38|0|0|0|0.02|15|800|6|20|0|0|ZZ:11|4|50|5|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|1|-1|8|0|0|1|100|0.8|2|8|8|0|0|1|0|0|38|0|0|0|0.02|15|800|6|-1|-1|8|0|0|1|100|0.8|2|8|8|0|0|1|0|0|38|0|0|0|0.02|15|800|6|20|0|0|ZZ:12|4|50|5|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|1|-1|8|0|0|1|100|0.8|2|8|8|0|0|1|0|0|38|0|0|0|0.02|15|800|6|-1|-1|8|0|0|1|100|0.8|2|8|8|0|0|1|0|0|38|0|0|0|0.02|15|800|6|20|0|0|ZZ:13|4|50|5|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|1|-1|8|0|0|1|100|0.8|2|8|8|0|0|1|0|0|38|0|0|0|0.02|15|800|6|-1|-1|8|0|0|1|100|0.8|2|8|8|0|0|1|0|0|38|0|0|0|0.02|15|800|6|20|0|0|ZZ:14|4|50|5|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|1|-1|8|0|0|1|100|0.8|2|8|8|0|0|1|0|0|38|0|0|0|0.02|15|800|6|-1|-1|8|0|0|1|100|0.8|2|8|8|0|0|1|0|0|38|0|0|0|0.02|15|800|6|20|0|0|ZZ:15|4|50|5|1|4|2.5|0.1875|0.028125|50|300|3|200|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|5|2|1|-1|8|0|0|1|100|0.8|2|8|8|0|0|1|0|0|38|0|0|0|0.02|15|800|6|-1|-1|8|0|0|1|100|0.8|2|8|8|0|0|1|0|0|38|0|0|0|0.02|15|800|6|20|0|0|ZZ:";

                                                                                     String result = "";
                                                                                     if (teamid == 1)
                                                                                     {
                                                                                                     result = team1;
                                                                                     }
                                                                                     if (teamid == 2)
                                                                                     {
                                                                                                     result = team2;
                                                                                     }
                                                                                     if (teamid == 3)
                                                                                     {
                                                                                                     result = team3;
                                                                                     }
                                                                                     if (teamid == 4)
                                                                                     {
                                                                                                     result = team4;
                                                                                     }
                                                                                     if (teamid == 5)
                                                                                     {
                                                                                                     result = team5;
                                                                                     }
                                                                                     Random rand = new Random();
                                                                                     int eteamid = rand.nextInt(5) + 1;

                                                                                     while (eteamid == teamid)
                                                                                     {
                                                                                                     eteamid = rand.nextInt(5) + 1;
                                                                                     }
                                                                                     if (eteamid == 1)
                                                                                     {
                                                                                                     result = result + team1;
                                                                                     }
                                                                                     if (eteamid == 2)
                                                                                     {
                                                                                                     result = result + team2;
                                                                                     }
                                                                                     if (eteamid == 3)
                                                                                     {
                                                                                                     result = result + team3;
                                                                                     }
                                                                                     if (eteamid == 4)
                                                                                     {
                                                                                                     result = result + team4;
                                                                                     }
                                                                                     if (eteamid == 5)
                                                                                     {
                                                                                                     result = result + team5;
                                                                                     }

                                                                                     Log.d(TAG, "Skirmish:result:" + result);
                                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.Map3DActivity.update");
                                                                                     if (!result.equals(""))
                                                                                     {
                                                                                                     String battlefile = "";
                                                                                                     String battleresult = "";
                                                                                                     // for now do locally.....
                                                                                                     String opath = Config.getStorageFolder(UploadService.this);
                                                                                                     Log.i(TAG, "simulating");
                                                                                                     Simulator sim = new Simulator(result, opath, UploadService.this, true);
                                                                                                     battlefile = sim.getBattleFile();
                                                                                                     battleresult = sim.getBattleResult();
                                                                                                     if (battleresult.length() > 0)
                                                                                                     {
                                                                                                                     battleresult = battleresult + "00"; // for now....
                                                                                                     }
                                                                                                     // String result2 = "";
                                                                                                     // String url2 = URL_UPLOADWCBATTLERESULT + "RS=" + battleresult;
                                                                                                     // result2 = HTTPGet.GetURL(url2);
                                                                                                     // Log.i(TAG,"result2 skirmish battle:"+result2);
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.Map3DActivity.resultcode", true);
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.Map3DActivity.battlefile", battlefile);
                                                                                     }
                                                                                     else
                                                                                     {
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.Map3DActivity.resultcode", false);
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.Map3DActivity.failurereasoncode", NETWORK_GENERALERROR);
                                                                                     }
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                     sendBroadcast(broadcastintent);
                                                                                     stopSelf(servid);
                                                                     }
                                                     }).start();

                                     }
                     }
                     if (action.equals("com.lloydm.geosword.common.UploadService.modifyai.update"))
                     {
                                     // update ai slider information...
                                     // get the get slider values.....
                                     final int shipid = intent.getIntExtra("com.lloydm.geosword.common.UploadService.shipid", 0);
                                     final int playerid = intent.getIntExtra("com.lloydm.geosword.common.UploadService.playerid", 0);
                                     final int geindex = intent.getIntExtra("com.lloydm.geosword.common.UploadService.geindex", 0);
                                     final int valint = intent.getIntExtra("com.lloydm.geosword.common.UploadService.valint", 0);
                                     final int servid = startId;
                                     new Thread(new Runnable()
                                     {
                                                     @Override
                                                     public void
run()
                                                     {
                                                                     getuser();
                                                                     if (notloggedin())
                                                                     {
                                                                                     // return a fail result
                                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.ModifyAIActivity.update");
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ModifyAIActivity.resultcode", false);
                                                                                     if (weberror)
                                                                                     {
                                                                                                     // most likely a connection failure of some sort...
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ModifyAIActivity.authenticationerror", LOGIN_WEB_ERROR);
                                                                                     }
                                                                                     else
                                                                                     {
                                                                                                     // appears that the user may not actually have a
                                                                                                     // login....or at least those credentials are
                                                                                                     // wrong....
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ModifyAIActivity.authenticationerror", LOGIN_NOT_FOUND);
                                                                                     }
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                     sendBroadcast(broadcastintent);
                                                                                     stopSelf(servid);
                                                                                     return;
                                                                     }
                                                                     String result = "";
                                                                     String url = URL_SETAISLIDERVALUE + "valint=" + valint + "&geindex=" + geindex + "&pid=" + playerid + "&sid=" + shipid;
                                                                     url = url + "&encodedusername=" + encodedusername + "&encodeduserpass=" + encodeduserpass;
                                                                     result = HTTPGet.GetURL(url);
                                                                     Log.d(TAG, "set slider - result:" + result);

                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.ModifyAIActivity.update");
                                                                     if (!result.equals("T"))
                                                                     {
                                                                                     // website error most likely...
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ModifyAIActivity.resultcode", false);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ModifyAIActivity.failurereasoncode", NETWORK_GENERALERROR);
                                                                     }
                                                                     else
                                                                     {
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ModifyAIActivity.resultcode", true);
                                                                     }
                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                     sendBroadcast(broadcastintent);
                                                                     stopSelf(servid);
                                                     }
                                     }).start();
                     }
                     if (action.equals("com.lloydm.geosword.common.UploadService.continue.load"))
                     {
                                     // get the get slider values.....
                                     final int servid = startId;
                                     new Thread(new Runnable()
                                     {
                                                     @Override
                                                     public void
run()
                                                     {
                                                                     getuser();
                                                                     if (notloggedin())
                                                                     {
                                                                                     // return a fail result
                                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.ContinueGameActivity.load");
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ContinueGameActivity.resultcode", false);
                                                                                     if (weberror)
                                                                                     {
                                                                                                     // most likely a connection failure of some sort...
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ContinueGameActivity.authenticationerror", LOGIN_WEB_ERROR);
                                                                                     }
                                                                                     else
                                                                                     {
                                                                                                     // appears that the user may not actually have a
                                                                                                     // login....or at least those credentials are
                                                                                                     // wrong....
                                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ContinueGameActivity.authenticationerror", LOGIN_NOT_FOUND);
                                                                                     }
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                                     sendBroadcast(broadcastintent);
                                                                                     stopSelf(servid);
                                                                                     return;
                                                                     }
                                                                     String result = "";
                                                                     String url = URL_GETMYONLINEGAMES + "&encodedusername=" + encodedusername + "&encodeduserpass=" + encodeduserpass;
                                                                     result = HTTPGet.GetURL(url);
                                                                     Log.d(TAG, "get my games - result:" + result);
                                                                     Intent broadcastintent = new Intent("com.lloydm.geosword.activities.ContinueGameActivity.load");
                                                                     if (result.equals(""))
                                                                     {
                                                                                     // website error most likely...
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ContinueGameActivity.resultcode", false);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ContinueGameActivity.failurereasoncode", NETWORK_GENERALERROR);
                                                                     }
                                                                     else
                                                                     {
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ContinueGameActivity.resultcode", true);
                                                                                     broadcastintent.putExtra("com.lloydm.geosword.activities.ContinueGameActivity.games", result);
                                                                     }
                                                                     broadcastintent.putExtra("com.lloydm.geosword.common.UploadService.uniqueid", uid);
                                                                     sendBroadcast(broadcastintent);
                                                                     stopSelf(servid);
                                                     }
                                     }).start();

                     }
                     return START_NOT_STICKY;
     }

     @Override
     public void onDestroy()
     {

     }

     private void sendthefile(final String filename, final int fleetatt, final int fleetdef, final String battleresult)
     {
                     HttpClient httpClient = new DefaultHttpClient();
                     HttpParams httpParams = new BasicHttpParams();
                     HttpConnectionParams.setConnectionTimeout(httpParams, 5000);
                     HttpConnectionParams.setSoTimeout(httpParams, 5000);
                     httpClient = new DefaultHttpClient(httpParams);
                     HttpPost httppost = new HttpPost(Config.WEBREPLAYTRANSFERPATH + "?encodedusername=" + encodedusername + "&encodeduserpass=" + encodeduserpass + "&FA=" + fleetatt + "&FD=" + fleetdef + "&RS=" + battleresult);
                     String boundary = "-------------"
+
System.currentTimeMillis();
                     httppost.setHeader("Content-type", "multipart/form-data; boundary=" + boundary);
                     String response = "";
                     try
                     {
                                     MultipartEntityBuilder builder = MultipartEntityBuilder.create();
                                     builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
                                     builder.setBoundary(boundary);
                                     final File file = new File(filename);
                                     FileBody fb = new FileBody(file);
                                     builder.addPart("file", fb);
                                     httppost.setEntity(builder.build());
                                     response = EntityUtils.toString(httpClient.execute(httppost).getEntity(), "UTF-8");
                                     Log.i(TAG, "WEB RESPONSE:" + response);

                                     return;
                     }
                     catch (IOException e)
                     {
                                     e.printStackTrace();
                     }
                     Log.e(TAG, "ERROR SENDING FILE");
     }

     public void saveprefs(String name, String value)
     {
                     if (prefs == null)
                     {
                                     prefs = getSharedPreferences("com.lloydm.geosword.common.stdgameprefs", MODE_PRIVATE);
                     }
                     prefsedit = prefs.edit();
                     prefsedit.putString(name, value);
                     prefsedit.commit();
     }

     public String getprefs(String name, String defvalue)
     {
                     if (prefs == null)
                     {
                                     prefs = getSharedPreferences("com.lloydm.geosword.common.stdgameprefs", MODE_PRIVATE);
                     }
                     return prefs.getString(name, defvalue);
     }

}