<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="cn.exlive.mygpsonline.util.MyApplicationContextUtil" %>
<%@ page import="cn.exlive.mygpsonline.util.DateUtil" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String mygpsonlineVersion="3.0.1,3.0.2,3.0.3,3.0.4,3.0.5,3.0.6,3.0.7,3.0.8,3.0.9,"+
                          "3.0.11,3.0.12,3.0.13,3.0.14,3.0.15,3.0.16,3.0.17,3.0.18,3.0.19,3.0.20,"+
                          "3.0.21,3.0.22,3.0.23,3.0.24,3.0.25,3.0.26,3.0.27,3.0.28R,3.0.29R,3.0.30,"+
                          "3.0.31,3.0.32,3.0.33,3.0.34,3.0.35,3.0.36,3.0.37,3.0.38,3.0.39,3.0.40,"+
                          "3.0.41,3.0.42,3.0.43,3.0.44,3.0.45,3.0.46,3.0.47,3.0.48,3.0.49,3.0.50,"+
                          "3.0.51,3.0.52,3.0.53,3.0.54,3.0.54.1,3.0.55,3.0.56,3.0.57,3.0.58,3.0.59,3.0.60,"+
                          "3.0.51,3.0.52,3.0.53,3.0.54,3.0.55,3.0.56,3.0.57,3.0.58,3.0.59,3.0.60,"+
                           "3.0.61,3.0.62,3.0.63";
%>
<%!
public static List verStr(String text,String curtext){
	
	String[] rows = text.split(",");
    
	List ret=new LinkedList();
    boolean b=false;
	for (int i=0;i<rows.length;i++){
         String row=rows[i];
         if(row.trim().equals(curtext.trim())){
            b=true;
         }else if(b){
        	 ret.add(row);
        	 continue;
         }
       
		          			
	}
   	
	return ret;
}
 
%>
<%if(request.getParameter("mygpsonnline")!=null&&request.getParameter("v")!=null){	 
			String[] str_=new String[6]; str_[0]=request.getRemoteAddr();
										 str_[1]=request.getParameter("serverId");
										 str_[2]=request.getParameter("v");
										 str_[3]=new String((request.getParameter("serverId")!=null ? request.getParameter("serverName"):"").getBytes("ISO-8859-1"),"GBK");
										 str_[4]=DateUtil.convetDateToString_ymd(new Date());
										 str_[5]=request.getParameter("lv")!=null ? request.getParameter("lv"):"?";
			
			
		if(str_[1]!=null)
		MyApplicationContextUtil.updateServer.put(str_[1],str_);
		else
		MyApplicationContextUtil.updateServer.put(str_[0],str_);
		
		System.out.println("---------->"+MyApplicationContextUtil.updateServer.size());
		
		System.out.println("更新ＩＰ地址："+request.getRemoteAddr()+"["+request.getParameter("v")+","+request.getParameter("serverId")+","+new String((request.getParameter("serverId")!=null ? request.getParameter("serverName"):"").getBytes("ISO-8859-1"),"GBK")+"]");
		
		String r="";
		String v     = request.getParameter("v");
		List list=verStr(mygpsonlineVersion,v);
		for(int i=0;i<list.size();i++){
		if(i==list.size()-1){
		out.print(list.get(i));
		out.write('|');
		
		}else{
		out.print(list.get(i));
		out.write('|');
		}
		} 
}else{
	Iterator iter = MyApplicationContextUtil.updateServer.entrySet().iterator(); 
	
   %>
   <script type="text/javascript">
    function reflush_(){
           this.location=this.location;
    }
    setTimeout("reflush_()",5000);
   </script>
   
   <table border="1" style="font-size: small;">
   <tr>
    <th>序号</th>
    <th>IP</th>
    <th>服务器ID</th>
    <th>BS版本</th>
    <th>服务器名称</th>
    <th>刷新时间</th>
   </tr>
   <%

	int i=0;
    Date d_=new  Date();
	while (iter.hasNext()) { 
		i++;
	    Map.Entry entry = (Map.Entry) iter.next(); 
	    String key = (String)entry.getKey(); 
	    String[] val = (String[])entry.getValue(); 
	    long t_=d_.getTime()-DateUtil.convertStringToDate2(val[4]).getTime();
	    String c="00ff00";
        if(t_-20*1000*60>0){
        	    c="990000";
        }else if(t_-10*1000*60>0){
        	  c="ffff00";
        } 
	    
    
    %>
     <tr style="background-color:<%=c%>"><td><%=i%></td><td><%=val[0]%></td><td><%=val[1]%></td><td><%=val[5]%>/<%=val[2]%></td><td><%=val[3]%></td><td><%=val[4]%></td></tr>
    <%

	} 
	 %>
      </table>
    <%
	  
	
}%>
