<commit_before>package com.chess.genesis;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import java.io.IOException;
import java.net.SocketException;
import org.json.JSONException;
import org.json.JSONObject;

class NetworkClient implements Runnable
{
	public final static int NONE = 0;
	public final static int LOGIN = 1;
	public final static int REGISTER = 2;
	public final static int JOIN_GAME = 3;
	public final static int NEW_GAME = 4;
	public final static int READ_INBOX = 5;
	public final static int CLEAR_INBOX = 6;
	public final static int GAME_STATUS = 7;
	public final static int GAME_INFO = 8;
	public final static int SUBMIT_MOVE = 9;
	public final static int SUBMIT_MSG = 10;
	public final static int SYNC_GAMIDS = 11;
	public final static int GAME_SCORE = 12;
	public final static int GAME_DATA = 13;
	public final static int RESIGN_GAME = 14;
	public final static int SYNC_LIST = 15;

	private final Context context;
	private final Handler callback;
	
	private JSONObject json;
	private int fid = NONE;
	private boolean loginRequired;
	private boolean error = false;

	public NetworkClient(final Context _context, final Handler handler)
	{
		callback = handler;
		context = _context;
	}

	private boolean relogin(final SocketClient net)
	{
		if (SocketClient.isLoggedin)
			return true;

		final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
		final String username = pref.getString("username", "!error!");
		final String password = pref.getString("passhash", <PASSWORD>!");

		JSONObject json2 = new JSONObject();

		try {
			try {
				json2.put("request", "login");
				json2.put("username", username);
				json2.put("passhash", Crypto.LoginKey(password));
			} catch (JSONException e) {
				e.printStackTrace();
				throw new RuntimeException();
			}
		} catch (SocketException e) {
			json2 = new JSONObject();
			try {
				json2.put("result", "error");
				json2.put("reason", "Can't contact server for sending data");
			} catch (JSONException j) {
				j.printStackTrace();
				throw new RuntimeException();
			}
			error = true;
		} catch (IOException e) {
			json2 = new JSONObject();
			try {
				json2.put("result", "error");
				json2.put("reason", "Lost connection durring sending data");
			} catch (JSONException j) {
				j.printStackTrace();
				throw new RuntimeException();
			}
			error = true;
		}
		if (error) {
			callback.sendMessage(Message.obtain(callback, fid, json2));
			error = false;
			return false;
		}

		try {
			net.write(json2);
		} catch (SocketException e) {
			json2 = new JSONObject();
			try {
				json2.put("result", "error");
				json2.put("reason", "Can't contact server for sending data");
			} catch (JSONException j) {
				j.printStackTrace();
				throw new RuntimeException();
			}
			error = true;
		} catch (IOException e) {
			json2 = new JSONObject();
			try {
				json2.put("result", "error");
				json2.put("reason", "Lost connection durring sending data");
			} catch (JSONException j) {
				j.printStackTrace();
				throw new RuntimeException();
			}
			error = true;
		}
		if (error) {
			callback.sendMessage(Message.obtain(callback, fid, json2));
			error = false;
			return false;
		}

		try {
			json2 = net.read();
		} catch (SocketException e) {
			json2 = new JSONObject();
			try {
				json2.put("result", "error");
				json2.put("reason", "Can't contact server for recieving data");
			} catch (JSONException j) {
				j.printStackTrace();
				throw new RuntimeException();
			}
		} catch (IOException e) {
			json2 = new JSONObject();
			try {
				json2.put("result", "error");
				json2.put("reason", "Lost connection durring recieving data");
			} catch (JSONException j) {
				j.printStackTrace();
				throw new RuntimeException();
			}
		} catch (JSONException e) {
			json2 = new JSONObject();
			try {
				json2.put("result", "error");
				json2.put("reason", "Server response illogical");
			} catch (JSONException j) {
				j.printStackTrace();
				throw new RuntimeException();
			}
		}
		if (error) {
			callback.sendMessage(Message.obtain(callback, fid, json2));
			error = false;
			return false;
		}

		try {
			if (!json2.getString("result").equals("ok")) {
				callback.sendMessage(Message.obtain(callback, fid, json2));
				return false;
			}
			SocketClient.isLoggedin = true;
			return true;
		} catch (JSONException e) {
			e.printStackTrace();
			throw new RuntimeException();
		}
	}

	public void run()
	{
		final SocketClient net = new SocketClient();
		JSONObject json2 = null;

		if (error) {
			error = false;
			net.disconnect();
			return;
		} else if (loginRequired && !relogin(net)) {<commit_msg>fix strange Java bug when using static refference to class variable<commit_after>package com.chess.genesis;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import java.io.IOException;
import java.net.SocketException;
import org.json.JSONException;
import org.json.JSONObject;

class NetworkClient implements Runnable
{
	public final static int NONE = 0;
	public final static int LOGIN = 1;
	public final static int REGISTER = 2;
	public final static int JOIN_GAME = 3;
	public final static int NEW_GAME = 4;
	public final static int READ_INBOX = 5;
	public final static int CLEAR_INBOX = 6;
	public final static int GAME_STATUS = 7;
	public final static int GAME_INFO = 8;
	public final static int SUBMIT_MOVE = 9;
	public final static int SUBMIT_MSG = 10;
	public final static int SYNC_GAMIDS = 11;
	public final static int GAME_SCORE = 12;
	public final static int GAME_DATA = 13;
	public final static int RESIGN_GAME = 14;
	public final static int SYNC_LIST = 15;

	private final Context context;
	private final Handler callback;
	
	private JSONObject json;
	private int fid = NONE;
	private boolean loginRequired;
	private boolean error = false;

	public NetworkClient(final Context _context, final Handler handler)
	{
		callback = handler;
		context = _context;
	}

	private boolean relogin(final SocketClient net)
	{
		if (net.isLoggedin)
			return true;

		final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
		final String username = pref.getString("username", "!error!");
		final String password = pref.getString("passhash", <PASSWORD>!");

		JSONObject json2 = new JSONObject();

		try {
			try {
				json2.put("request", "login");
				json2.put("username", username);
				json2.put("passhash", Crypto.LoginKey(password));
			} catch (JSONException e) {
				e.printStackTrace();
				throw new RuntimeException();
			}
		} catch (SocketException e) {
			json2 = new JSONObject();
			try {
				json2.put("result", "error");
				json2.put("reason", "Can't contact server for sending data");
			} catch (JSONException j) {
				j.printStackTrace();
				throw new RuntimeException();
			}
			error = true;
		} catch (IOException e) {
			json2 = new JSONObject();
			try {
				json2.put("result", "error");
				json2.put("reason", "Lost connection durring sending data");
			} catch (JSONException j) {
				j.printStackTrace();
				throw new RuntimeException();
			}
			error = true;
		}
		if (error) {
			callback.sendMessage(Message.obtain(callback, fid, json2));
			error = false;
			return false;
		}

		try {
			net.write(json2);
		} catch (SocketException e) {
			json2 = new JSONObject();
			try {
				json2.put("result", "error");
				json2.put("reason", "Can't contact server for sending data");
			} catch (JSONException j) {
				j.printStackTrace();
				throw new RuntimeException();
			}
			error = true;
		} catch (IOException e) {
			json2 = new JSONObject();
			try {
				json2.put("result", "error");
				json2.put("reason", "Lost connection durring sending data");
			} catch (JSONException j) {
				j.printStackTrace();
				throw new RuntimeException();
			}
			error = true;
		}
		if (error) {
			callback.sendMessage(Message.obtain(callback, fid, json2));
			error = false;
			return false;
		}

		try {
			json2 = net.read();
		} catch (SocketException e) {
			json2 = new JSONObject();
			try {
				json2.put("result", "error");
				json2.put("reason", "Can't contact server for recieving data");
			} catch (JSONException j) {
				j.printStackTrace();
				throw new RuntimeException();
			}
		} catch (IOException e) {
			json2 = new JSONObject();
			try {
				json2.put("result", "error");
				json2.put("reason", "Lost connection durring recieving data");
			} catch (JSONException j) {
				j.printStackTrace();
				throw new RuntimeException();
			}
		} catch (JSONException e) {
			json2 = new JSONObject();
			try {
				json2.put("result", "error");
				json2.put("reason", "Server response illogical");
			} catch (JSONException j) {
				j.printStackTrace();
				throw new RuntimeException();
			}
		}
		if (error) {
			callback.sendMessage(Message.obtain(callback, fid, json2));
			error = false;
			return false;
		}

		try {
			if (!json2.getString("result").equals("ok")) {
				callback.sendMessage(Message.obtain(callback, fid, json2));
				return false;
			}
			net.isLoggedin = true;
			return true;
		} catch (JSONException e) {
			e.printStackTrace();
			throw new RuntimeException();
		}
	}

	public void run()
	{
		final SocketClient net = new SocketClient();
		JSONObject json2 = null;

		if (error) {
			error = false;
			net.disconnect();
			return;
		} else if (loginRequired && !relogin(net)) {
{'fraction_non_alphanumeric': 0.12121212121212122, 'fraction_numerical': 0.011494252873563218, 'mean_word_length': 3.6214389183969096, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2353389', 'n_tokens_mistral': 3518, 'n_tokens_neox': 2943, 'n_words': 870}