/*
 * Generated by the Jasper component of Apache Tomcat
 * Version: Apache Tomcat/7.0.19
 * Generated at: 2012-12-23 21:45:56 UTC
 * Note: The last modified time of this file was set to
 *       the last modified time of the source file after
 *       generation to assist with modification tracking.
 */
package org.apache.jsp.addons.Spouse_0020Manager;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import protocol.*;
import org.apache.commons.lang.StringEscapeUtils;
import java.io.*;

public final class index_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static final javax.servlet.jsp.JspFactory _jspxFactory =
          javax.servlet.jsp.JspFactory.getDefaultFactory();

  private static java.util.Map<java.lang.String,java.lang.Long> _jspx_dependants;

  static {
    _jspx_dependants = new java.util.HashMap<java.lang.String,java.lang.Long>(1);
    _jspx_dependants.put("/addons/Spouse Manager/../../WEB-INF/.pwadminconf.jsp", Long.valueOf(1356261856000L));
  }

  private javax.el.ExpressionFactory _el_expressionfactory;
  private org.apache.tomcat.InstanceManager _jsp_instancemanager;

  public java.util.Map<java.lang.String,java.lang.Long> getDependants() {
    return _jspx_dependants;
  }

  public void _jspInit() {
    _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
    _jsp_instancemanager = org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(getServletConfig());
  }

  public void _jspDestroy() {
  }

  public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response)
        throws java.io.IOException, javax.servlet.ServletException {

    final javax.servlet.jsp.PageContext pageContext;
    javax.servlet.http.HttpSession session = null;
    final javax.servlet.ServletContext application;
    final javax.servlet.ServletConfig config;
    javax.servlet.jsp.JspWriter out = null;
    final java.lang.Object page = this;
    javax.servlet.jsp.JspWriter _jspx_out = null;
    javax.servlet.jsp.PageContext _jspx_page_context = null;


    try {
      response.setContentType("text/html");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write('\n');
      out.write('\n');
      out.write('\n');
      out.write('\n');

//-------------------------------------------------------------------------------------------------------------------------
//------------------------------- SETTINGS --------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------

	// pwadmin access password as md5 encrypted string
	// default password is root -> 63a9f0ea7bb98050796b649e85481845
	String iweb_password = "f67e209e9b8164dcb6812b9ac4357ed1";

	// connection settings to the mysql pw database
	String db_host = "localhost";
	String db_port = "3306";
	String db_user = "root";
	String db_password = "1011";
	String db_database = "pw";

	// Type of your items database required for mapping id's to names
	// Options are my or pwi
	String item_labels = "pwi";

	// Absolute path to your PW-Server main directory (startscript, stopscript, /gamed)
	// requires a tailing slash
	String pw_server_path = "/root/";

	// If you have hundreds of characters or heavy web acces through this site
	// It is recommend to turn the realtime character list feature off (false)
	// to prevent server from overload injected by character list generation
	boolean enable_character_list = true;

	String pw_server_name = "Your PW Servername";
	String pw_server_description = "+ Your server description here<br>+ 2 x 2.4 GHz, 2048 MB RAM, 100 MBit LAN<br>+ all dungeons open<br>+ tideborn nirvana weapons<br>+ World bosses";

//-------------------------------------------------------------------------------------------------------------------------
//----------------------------- END SETTINGS ------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------

	String pw_server_exp = "?";
	String pw_server_sp = "?";
	String pw_server_drop = "?";
	String pw_server_coins = "?";

	BufferedReader bfr = new BufferedReader(new FileReader(pw_server_path + "gamed/ptemplate.conf"));

	String row;
	while((row = bfr.readLine()) != null)
	{
		row = row.replaceAll("\\s", "");
		if(row.indexOf("exp_bonus=") != -1)
		{
			int pos = row.length();
			if(row.indexOf("#") != -1)
			{
				pos = row.indexOf("#");
			}
			pw_server_exp = row.substring(10, pos);
		}
		if(row.indexOf("sp_bonus=") != -1)
		{
			int pos = row.length();
			if(row.indexOf("#") != -1)
			{
				pos = row.indexOf("#");
			}
			pw_server_sp = row.substring(9, pos);
		}
		if(row.indexOf("drop_bonus=") != -1)
		{
			int pos = row.length();
			if(row.indexOf("#") != -1)
			{
				pos = row.indexOf("#");
			}
			pw_server_drop = row.substring(11, pos);
		}
		if(row.indexOf("money_bonus=") != -1)
		{
			int pos = row.length();
			if(row.indexOf("#") != -1)
			{
				pos = row.indexOf("#");
			}
			pw_server_coins = row.substring(12, pos);
		}
	}

	bfr.close();

	if(request.getSession().getAttribute("items") == null)
	{
		String[] items = new String[30001];

		try
		{
			bfr = new BufferedReader(new InputStreamReader(new FileInputStream(new File(request.getRealPath("/include/items") + "/default.dat")), "UTF8"));
			if(item_labels.compareTo("my") == 0)
			{
				bfr = new BufferedReader(new InputStreamReader(new FileInputStream(new File(request.getRealPath("/include/items") + "/my.dat")), "UTF8"));
			}
			if(item_labels.compareTo("pwi") == 0)
			{
				bfr = new BufferedReader(new InputStreamReader(new FileInputStream(new File(request.getRealPath("/include/items") + "/pwi.dat")), "UTF8"));
			}
			int count = 0;
			while((row = bfr.readLine()) != null && count < 30001)
			{
				items[count] = row;
				count++;
			}
			bfr.close();
		}
		catch(Exception e)
		{
		}

		request.getSession().setAttribute("items", items);
	}

      out.write('\n');
      out.write('\n');
      out.write('\n');

	Boolean same_sex = false;

      out.write('\n');
      out.write('\n');

	String message = "<br>";
	boolean allowed = false;

	if(request.getSession().getAttribute("ssid") == null)
	{
		message = "<font color=\"#ee0000\"><b>Login to use Marriage...</b></font>";
	}
	else
	{
		allowed = true;
	}

      out.write('\n');
      out.write('\n');

	if(allowed && request.getParameter("process") != null)
	{
		if(request.getParameter("process").compareTo("marry") == 0)
		{
			if(request.getParameter("groom") != null && request.getParameter("bride") != null)
			{
				message = "";

				int groomid = GameDB.getRoleIdByName(request.getParameter("groom"));
				if(groomid < 0)
				{
					try
					{
						groomid = Integer.parseInt(request.getParameter("groom"));
					}
					catch(Exception e)
					{
						message += "<font color=\"#ee0000\"><b>Invalid Groom</b></font><br>";
					}
				}

				int brideid = GameDB.getRoleIdByName(request.getParameter("bride"));
				if(brideid < 0)
				{
					try
					{
						brideid = Integer.parseInt(request.getParameter("bride"));
					}
					catch(Exception e)
					{
						message += "<font color=\"#ee0000\"><b>Invalid Bride</b></font><br>";
					}
				}

				if(groomid > 31 && brideid > 31)
				{
					if(groomid != brideid)
					{
						XmlRole.Role groom = XmlRole.getRoleFromDB(groomid);
						XmlRole.Role bride = XmlRole.getRoleFromDB(brideid);

						if(groom != null && bride != null)
						{
							if(groom.base.reserved1 == 0 && bride.base.reserved1 == 0)
							{
								if(same_sex || groom.base.gender != bride.base.gender)
								{
									try
									{
										//role.base.id = groomid;

										groom.base.reserved1 = brideid;
										bride.base.reserved1 = groomid;

										XmlRole.putRoleToDB(groomid, groom);
										XmlRole.putRoleToDB(brideid, bride);

										message += "<font color=\"#00cc00\"><b>Characters Married</b></font>";
									}
									catch(Exception e)
									{
										message += "<font color=\"#ee0000\"><b>Marriage Failed</b></font>";
									}
								}
								else
								{
									message += "<font color=\"#ee0000\"><b>Same Gender</b></font>";
								}
							}
							else
							{
								message += "<font color=\"#ee0000\"><b>Groom or Bride already Married</b></font>";
							}
						}
						else
						{
							message += "<font color=\"#ee0000\"><b>Invalid Groom or Bride</b></font>";
						}
					}
					else
					{
						message += "<font color=\"#ee0000\"><b>Groom and Bride are Identical</b></font>";
					}
				}
				else
				{
					//message += "<font color=\"#ee0000\"><b>Invalid Spouse (ID < 32)</b></font>";
				}
			}
		}

		if(request.getParameter("process").compareTo("divorce") == 0)
		{
			if(request.getParameter("spouse") != null)
			{
				message = "";

				int groomid = GameDB.getRoleIdByName(request.getParameter("spouse"));
				int brideid = -1;

				if(groomid < 0)
				{
					try
					{
						groomid = Integer.parseInt(request.getParameter("spouse"));
					}
					catch(Exception e)
					{
						message += "<font color=\"#ee0000\"><b>Invalid Spouse</b></font><br>";
					}
				}

				if(groomid > 31)
				{
					XmlRole.Role groom = XmlRole.getRoleFromDB(groomid);

					if(groom != null)
					{
						if(groom.base.reserved1 != 0)
						{
							brideid = groom.base.reserved1;

							try
							{
								groom.base.reserved1 = 0;
								XmlRole.putRoleToDB(groomid, groom);
								message += "<font color=\"#00cc00\"><b>Groom Divorced</b></font>";
							}
							catch(Exception e)
							{
								message += "<font color=\"#ee0000\"><b>Groom Divorce Failed</b></font>";
							}
						}
						else
						{
							message += "<font color=\"#ee0000\"><b>Groom already Divorced</b></font>";
						}
					}
					else
					{
						message += "<font color=\"#ee0000\"><b>Invalid Groom</b></font>";
					}
				}
				else
				{
					//message += "<font color=\"#ee0000\"><b>Invalid Groom (ID < 32)</b></font>";
				}

				message += "<br>";

				if(brideid > 31)
				{
					XmlRole.Role bride = XmlRole.getRoleFromDB(brideid);
					if(bride != null)
					{
						if(bride.base.reserved1 == groomid)
						{
							try
							{
								bride.base.reserved1 = 0;
								XmlRole.putRoleToDB(brideid, bride);
								message += "<font color=\"#00cc00\"><b>Bride Divorced</b></font>";
							}
							catch(Exception e)
							{
								message += "<font color=\"#ee0000\"><b>Bride Divorce Failed</b></font>";
							}
						}
						else
						{
							message += "<font color=\"#ee0000\"><b>Bride not married with Groom</b></font>";
						}
					}
					else
					{
						message += "<font color=\"#ee0000\"><b>Invalid Bride</b></font>";
					}
				}
				else
				{
					//message += "<font color=\"#ee0000\"><b>Invalid Bride (ID < 32)</b></font>";
				}
			}
		}
	}

      out.write("\n");
      out.write("\n");
      out.write("<html>\n");
      out.write("\n");
      out.write("<head>\n");
      out.write("\t<link rel=\"shortcut icon\" href=\"../../include/fav.ico\">\n");
      out.write("\t<link rel=\"stylesheet\" type=\"text/css\" href=\"../../include/style.css\">\n");
      out.write("</head>\n");
      out.write("\n");
      out.write("<body>\n");
      out.write("\n");
      out.write("<table align=\"center\" cellpadding=\"2\" cellspacing=\"0\" style=\"border: 1px solid #cccccc;\">\n");
      out.write("\t<tr>\n");
      out.write("\t\t<th colspan=\"3\" height=\"1\" style=\"padding: 5;\">\n");
      out.write("\t\t\t<b>SPOUSE MANAGER*</b>\n");
      out.write("\t\t</th>\n");
      out.write("\t</tr>\n");
      out.write("\t<tr>\n");
      out.write("\t\t<td align=\"center\" colspan=\"3\" height=\"1\">\n");
      out.write("\t\t\t");
 out.print(message); 
      out.write("\n");
      out.write("\t\t</td>\n");
      out.write("\t</tr>\n");
      out.write("\n");
      out.write("\t<form action=\"index.jsp?process=marry\" method=\"post\">\n");
      out.write("\t<tr bgcolor=\"#f0f0f0\">\n");
      out.write("\t\t<td align=\"center\" colspan=\"3\" height=\"1\">\n");
      out.write("\t\t\t<b>Marry</b>\n");
      out.write("\t\t</td>\n");
      out.write("\t</tr>\n");
      out.write("\t<tr>\n");
      out.write("\t\t<td align=\"left\">Groom + Bride:</td>\n");
      out.write("\t\t<td align=\"left\">\n");
      out.write("\t\t\t<input type=\"text\" name=\"groom\" style=\"width: 100px;\"></input> + <input type=\"text\" name=\"bride\" style=\"width: 100px;\">\n");
      out.write("\t\t</input></td>\n");
      out.write("\t\t<td align=\"center\" style=\"padding: 5;\">\n");
      out.write("\t\t\t<input type=\"image\" src=\"../../include/btn_submit.jpg\" style=\"border: 0;\"></input>\n");
      out.write("\t\t</td>\n");
      out.write("\t</tr>\n");
      out.write("\t</form>\n");
      out.write("\n");
      out.write("\t<form action=\"index.jsp?process=divorce\" method=\"post\">\n");
      out.write("\t<tr bgcolor=\"#f0f0f0\">\n");
      out.write("\t\t<td align=\"center\" colspan=\"3\" height=\"1\">\n");
      out.write("\t\t\t<b>Divorce</b>\n");
      out.write("\t\t</td>\n");
      out.write("\t</tr>\n");
      out.write("\t<tr>\n");
      out.write("\t\t<td align=\"left\">Spouse:</td>\n");
      out.write("\t\t<td align=\"left\">\n");
      out.write("\t\t\t<input type=\"text\" name=\"spouse\" style=\"width: 100%;\"></input>\n");
      out.write("\t\t</td>\n");
      out.write("\t\t<td align=\"center\" style=\"padding: 5;\">\n");
      out.write("\t\t\t<input type=\"image\" src=\"../../include/btn_submit.jpg\" style=\"border: 0;\"></input>\n");
      out.write("\t\t</td>\n");
      out.write("\t</tr>\n");
      out.write("\t</form>\n");
      out.write("\n");
      out.write("</table>\n");
      out.write("\n");
      out.write("<center>\n");
      out.write("\t<br>\n");
      out.write("\t*characters should be logged out\n");
      out.write("</center>\n");
      out.write("\n");
      out.write("</body>\n");
      out.write("\n");
      out.write("</html>");
    } catch (java.lang.Throwable t) {
      if (!(t instanceof javax.servlet.jsp.SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try { out.clearBuffer(); } catch (java.io.IOException e) {}
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
