using System;
using System.IO;
using UnityEngine;

public class MyMidlet
{
	public static string version = "3.7.3";

	public static sbyte PROVIDER;

	public static sbyte BIG_PROVIDER = 0;

	public static CCanvas canvas;

	public static MyMidlet instance;

	public static string IP = "27.0.14.69";

	public static int PORT = 19150;

	public static CPlayer myInfo;

	public static string AGENT;

	public static sbyte filePackVersion;

	public static bool[] isVip = new bool[10];

	public static bool isTeamClient = true;

	public static bool trainingSuccess;

	private bool isStartGame;

	public MyMidlet()
	{
		instance = this;
		initGame();
	}

	public void init()
	{
		try
		{
			StringReader stringReader = null;
			TextAsset textAsset = ResourcePath.LoadText(Main.res + "/provider");
			if (textAsset == null)
			{
				return;
			}
			stringReader = new StringReader(textAsset.text);
			if (stringReader != null)
			{
				string text = stringReader.ReadLine();
				if (text != null)
				{
					string text2 = text.ToString();
					PROVIDER = sbyte.Parse(text2.Trim());
				}
			}
		}
		catch (IOException)
		{
		}
		string text3 = CRes.loadIP();
		if (text3 != null)
		{
			try
			{
				int num = text3.IndexOf(":");
				string iP = text3.Substring(0, num);
				string s = text3.Substring(num + 1);
				IP = iP;
				PORT = int.Parse(s);
			}
			catch (Exception)
			{
			}
		}
		MessageHandler.gI().setGameLogicHandler(GameLogicHandler.gI());
		Session_ME.gI().setHandler(MessageHandler.gI());
		GameService.gI().setSession(Session_ME.gI());
	}

	protected void destroyApp(bool arg0)
	{
		if (canvas != null)
		{
			canvas.stopGame();
			canvas = null;
		}
		notifyDestroyed();
	}

	public void initGame()
	{
		instance = this;
		MotherCanvas.instance = new MotherCanvas();
		Session_ME.gI().setHandler(MessageHandler.gI());
		MessageHandler.gI().setGameLogicHandler(GameLogicHandler.gI());
		GameService.gI().setSession(Session_ME.gI());
		instance = this;
		canvas = new CCanvas();
		canvas.start();
		CRes.init();
	}

	protected void pauseApp()
	{
	}

	protected void startApp()
	{
		if (!isStartGame)
		{
			isStartGame = true;
		}
	}

	public void exit()
	{
		if (Main.clientType == 6)
		{
			Main.exit();
			return;
		}
		CCanvas.isRunning = false;
		mSystem.gcc();
		notifyDestroyed();
	}

	public void perform(int idAction, object p)
	{
		if (idAction == 1000)
		{
			CCanvas.startOKDlg(L.sendSuccess());
		}
		if (idAction == 1001)
		{
			CCanvas.startOKDlg(L.sendFail());
		}
		if (idAction == 1002)
		{
			exit();
		}
	}

	public void notifyDestroyed()
	{
		Main.exit();
	}

	public void platformRequest(string url)
	{
		Cout.LogWarning("PLATFORM REQUEST: " + url);
		Application.OpenURL(url);
	}
}
