[Jcrossclient-cvs] jcrossclient Metaserver.java,NONE,1.1 CFclient.java,1.32,1.33 Changelog,1.38,1.39
Status: Alpha
Brought to you by:
cavesomething
From: <jcr...@li...> - 2006-03-22 23:55:34
|
Update of /cvsroot/jcrossclient/jcrossclient In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28556 Modified Files: CFclient.java Changelog ServerCon.java Added Files: Metaserver.java Log Message: initial metaserver support Index: ServerCon.java =================================================================== RCS file: /cvsroot/jcrossclient/jcrossclient/ServerCon.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ServerCon.java 1 Feb 2006 19:14:29 -0000 1.4 --- ServerCon.java 22 Mar 2006 23:55:30 -0000 1.5 *************** *** 200,214 **** } ! public ServerCon(CFclient parent, String hostname) { ! //InputStream infromserv; tmpbuf = new byte[2]; // timesaver try{ mParent = parent; ! myconn = new Socket(hostname, 13327); ! //infromserv = myconn.getInputStream(); ! //fromserver = new BufferedInputStream(infromserv, 16384); mInStream = new DataInputStream(myconn.getInputStream()); - //toserver = new DataOutputStream(myconn.getOutputStream()); mBAOS = new ByteArrayOutputStream(0); mDOS = new DataOutputStream(mBAOS); --- 200,210 ---- } ! public ServerCon(CFclient parent, String hostname, int port) { tmpbuf = new byte[2]; // timesaver try{ mParent = parent; ! myconn = new Socket(hostname, port); mInStream = new DataInputStream(myconn.getInputStream()); mBAOS = new ByteArrayOutputStream(0); mDOS = new DataOutputStream(mBAOS); *************** *** 230,232 **** --- 226,232 ---- debug("GOT CONNECTION(I hope)"); } + + public ServerCon(CFclient parent, String hostname) { + this(parent, hostname, 13327); + } } --- NEW FILE: Metaserver.java --- /* * Copyright (c) 2006, Brendan Lally, bre...@gm... * * This file is part of jcrossclient. * * Jcrossclient is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. * * Jcrossclient is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with * Jcrossclient; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ import java.awt.*; import java.util.Vector; import java.awt.event.*; import java.net.*; import java.io.*; import java.lang.Integer; import java.util.*; class ServerData { String ip_address; int update_time; String hostname; int port; int player_count; String version; String comment; int bytes_in; int bytes_out; int uptime; public ServerData() { } void setIP(String ip) { ip_address = ip; } void setUpdateTime(String time) { update_time = Integer.parseInt(time); } /* If we have a hostname containing a colon, treat the bit after * the colon as a port number */ void setHostname(String host) { StringTokenizer parsehost = new StringTokenizer(host, ":"); hostname = parsehost.nextToken(); if (parsehost.hasMoreTokens()) port = Integer.parseInt(parsehost.nextToken()); } void setPlayerCount(String count) { player_count = Integer.parseInt(count); } void setVersion(String ver) { version = ver; } void setComment(String comm) { comment = comm; } void setBytesIn(String in_bytes) { bytes_in = Integer.parseInt(in_bytes); } void setBytesOut(String out_bytes) { bytes_in = Integer.parseInt(out_bytes); } void setUptime(String time) { uptime = Integer.parseInt(time); } } class Metaserver extends Canvas implements MouseListener, ActionListener { int objpixheight=MapWin.pixheight+8; CFclient toplevel; Socket metaserver; BufferedReader server_data; Vector Servers; int serversize=0; int winwidth=80; // recalc'd every time contents changed // but lets have a reasonable start! public Metaserver(CFclient tl) { toplevel = tl; addMouseListener(this); Servers = new Vector(); sync_to_metaserver(); } /* open a socket to the metaserver, parse the data recieved, and update the server list */ void sync_to_metaserver() { try { metaserver = new Socket("crossfire.real-time.com", 13326); server_data = new BufferedReader(new InputStreamReader(metaserver.getInputStream())); parse_metaserver(); metaserver.close(); } catch(UnknownHostException e) { debug("can't connect to metaserver"); return; } catch (IOException e) { debug("socket i/o error:"+e.getMessage()); return; } } /* read in the data on the socket, and populate the server list */ void parse_metaserver() throws IOException { String current_server; StringTokenizer parser; ServerData new_server; while ((current_server = server_data.readLine()) != null) { new_server = new ServerData(); try { parser = new StringTokenizer(current_server, "|"); new_server.setIP(parser.nextToken()); new_server.setUpdateTime(parser.nextToken()); new_server.setHostname(parser.nextToken()); new_server.setPlayerCount(parser.nextToken()); new_server.setVersion(parser.nextToken()); new_server.setComment(parser.nextToken()); new_server.setBytesIn(parser.nextToken()); new_server.setBytesOut(parser.nextToken()); Servers.add(new_server); System.out.println("new server " + new_server.hostname + " with " + new_server.player_count + " players"); } catch (NoSuchElementException e) { /* try and add the server anyway, we might have enough data to be useful */ Servers.add(new_server); System.out.println("broken server " + new_server.hostname + " with " + new_server.player_count + " players"); } } } public void actionPerformed(ActionEvent evt) { } void debug(String msg) { if(toplevel.debugflag) System.out.println(msg); } /* * It sucks that we have to register for ALL THESE * just to listen for mouse clicks. Sigh. * Dont forget to match up with the paint() order */ public void mouseClicked(MouseEvent evt) { } public void mouseEntered(MouseEvent evt) { } public void mouseExited(MouseEvent evt) { } public void mousePressed(MouseEvent evt) { } public void mouseReleased(MouseEvent evt) { } public void paint(Graphics gc) { gc.drawString("(Metaserver window)", 10,10); return; } } Index: CFclient.java =================================================================== RCS file: /cvsroot/jcrossclient/jcrossclient/CFclient.java,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** CFclient.java 12 Feb 2006 20:52:12 -0000 1.32 --- CFclient.java 22 Mar 2006 23:55:30 -0000 1.33 *************** *** 148,152 **** TalkWin talkwin; StatbarWin miscwin; ! MagicMap magicmap; public ScrollPane iscrollp, escrollp, sscrollp, spscrollp; Panel viewpane; --- 148,153 ---- TalkWin talkwin; StatbarWin miscwin; ! MagicMap magicmap; ! Metaserver metaserver; public ScrollPane iscrollp, escrollp, sscrollp, spscrollp; Panel viewpane; *************** *** 1257,1260 **** --- 1258,1262 ---- miscwin = new StatbarWin(this); magicmap = new MagicMap(this); + metaserver = new Metaserver(this); TabPanel leftside = new TabPanel(); *************** *** 1295,1298 **** --- 1297,1301 ---- viewpane.add("map", mapwin); viewpane.add("magicmap", magicmap); + viewpane.add("metaserver", metaserver); topside.add(viewpane); topside.add(miscwin); Index: Changelog =================================================================== RCS file: /cvsroot/jcrossclient/jcrossclient/Changelog,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** Changelog 20 Feb 2006 18:54:36 -0000 1.38 --- Changelog 22 Mar 2006 23:55:30 -0000 1.39 *************** *** 279,280 **** --- 279,287 ---- 20/02/2006 - Spell - Don't break if passed a zero as the skill number in an addspell packet + + 22/02/2006 - Metaserver - if there is no defined server to connect to, query the + metaserver at startup and parse its output for later use. + + ServerCon - Allow connections to non-standard ports + + CFclient - Add a metaserver pane to the main window. |