public class citGui {
- JFrame frame;
- CardLayout cdLayout;
- Container c;
- hostPanel hp;
- loginPanel lp;
- mainPanel mp;
- logoffPanel lfp;
-
- public citGui() {
- frame = new JFrame( "Shaggy" );
- c = frame.getContentPane();
-
- c.setLayout( cdLayout = new CardLayout() );
- c.add( "Host", hp = new hostPanel() );
- c.add( "Login", lp = new loginPanel() );
- c.add( "Main", mp = new mainPanel() );
- c.add( "Logoff", lfp = new logoffPanel() );
-
- frame.addWindowListener( new WindowAdapter() {
- public void windowClosing( WindowEvent e ) {
- citadel.me.closeFrame();
- System.exit( 0 );
- }
- });
-
- frame.pack();
- frame.setVisible( true );
- }
-
- public void showHostBrowser() {
- cdLayout.show( c, "Host" );
- hp.refresh();
- }
-
- public void showLoginPanel() {
- cdLayout.show( c, "Login" );
- lp.refresh();
- }
-
- public void showLoginPanel( String user, String pass ) {
- showLoginPanel();
- lp.setDefault( user, pass );
- if( (user == null) || (user.length()==0) ||
- (pass == null) || (pass.length()==0) ) return;
- citadel.me.authenticate( user, pass );
- }
-
- public void showMainPanel() {
- cdLayout.show( c, "Main" );
- mp.refresh();
- }
-
- public void showLogoffPanel() {
- cdLayout.show( c, "Logoff" );
- lfp.refresh();
- }
-
- public void errMsg( String reason ) {
- JOptionPane.showMessageDialog(frame,
- reason,
- "Inane error",
- JOptionPane.ERROR_MESSAGE);
- }
-
- public void warning( String text ) {
- JOptionPane.showMessageDialog(frame,
- text,
- "What is this?",
- JOptionPane.WARNING_MESSAGE);
- }
+ JFrame frame;
+ CardLayout cdLayout;
+ Container c;
+ hostPanel hp;
+ loginPanel lp;
+ mainPanel mp;
+ logoffPanel lfp;
+
+ public citGui() {
+ frame = new JFrame( "Shaggy" );
+ c = frame.getContentPane();
+
+ c.setLayout( cdLayout = new CardLayout() );
+ c.add( "Host", hp = new hostPanel() );
+ c.add( "Login", lp = new loginPanel() );
+ c.add( "Main", mp = new mainPanel() );
+ c.add( "Logoff", lfp = new logoffPanel() );
+
+ frame.addWindowListener( new WindowAdapter() {
+ public void windowClosing( WindowEvent e ) {
+ citadel.me.closeFrame();
+ System.exit( 0 );
+ }
+ });
+
+ frame.pack();
+ frame.setVisible( true );
+ }
+
+ public void showHostBrowser() {
+ cdLayout.show( c, "Host" );
+ hp.refresh();
+ }
+
+ public void showLoginPanel() {
+ cdLayout.show( c, "Login" );
+ lp.refresh();
+ }
+
+ public void showLoginPanel( String user, String pass ) {
+ showLoginPanel();
+ lp.setDefault( user, pass );
+ if( (user == null) || (user.length()==0) ||
+ (pass == null) || (pass.length()==0) ) return;
+ citadel.me.authenticate( user, pass );
+ }
+
+ public void showMainPanel() {
+ cdLayout.show( c, "Main" );
+ mp.refresh();
+ }
+
+ public void showLogoffPanel() {
+ cdLayout.show( c, "Logoff" );
+ lfp.refresh();
+ }
+
+ public void errMsg( String reason ) {
+ JOptionPane.showMessageDialog(frame,
+ reason,
+ "Inane error",
+ JOptionPane.ERROR_MESSAGE);
+ }
+
+ public void warning( String text ) {
+ JOptionPane.showMessageDialog(frame,
+ text,
+ "What is this?",
+ JOptionPane.WARNING_MESSAGE);
+ }
}
import java.util.*;
public class citReply {
- public static final int LISTING_FOLLOWS=100, OK=200, MORE_DATA=300,
- SEND_LISTING=400, ERROR=500, BINARY_FOLLOWS=600, SEND_BINARY=700,
- START_CHAT_MODE=800;
-
- int res_code;
- String line,data;
- Vector args, listing;
- boolean expressmsg;
-
- public citReply( String line ) {
- this.line = line;
-
- args = new Vector();
- listing = null;
- data = null;
- res_code = ERROR;
- expressmsg = false;
-
- if( line != null )
- parseLine();
- }
-
- public void parseLine() {
- try {
- res_code = Integer.parseInt( line.substring( 0, 3 ) );
- } catch( Exception e ) {};
-
- StringBuffer s = new StringBuffer();
-
- if( (line.length() > 3) && (line.charAt( 3 ) == '*') )
- expressmsg = true;
-
- for( int i = 4; i < line.length(); i++ ) {
- char c = line.charAt( i );
- if( c == '|' ) {
- args.addElement( s.toString() );
- s = new StringBuffer();
- }
- else
- s.append( c );
+ public static final int LISTING_FOLLOWS=100, OK=200, MORE_DATA=300,
+ SEND_LISTING=400, ERROR=500, BINARY_FOLLOWS=600, SEND_BINARY=700,
+ START_CHAT_MODE=800;
+
+ int res_code;
+ String line,data;
+ Vector args, listing;
+ boolean expressmsg;
+
+ public citReply( String line ) {
+ this.line = line;
+
+ args = new Vector();
+ listing = null;
+ data = null;
+ res_code = ERROR;
+ expressmsg = false;
+
+ if( line != null )
+ parseLine();
}
- if( s.length() != 0 ) args.addElement( s.toString() );
- }
+ public void parseLine() {
+ try {
+ res_code = Integer.parseInt( line.substring( 0, 3 ) );
+ } catch( Exception e ) {};
- public boolean expressMessage() {
- return expressmsg;
- }
+ StringBuffer s = new StringBuffer();
- public boolean listingFollows() {
- return res_code/100 == LISTING_FOLLOWS/100;
- }
+ if( (line.length() > 3) && (line.charAt( 3 ) == '*') )
+ expressmsg = true;
- public boolean ok() {
- return res_code/100 == OK/100;
- }
+ for( int i = 4; i < line.length(); i++ ) {
+ char c = line.charAt( i );
+ if( c == '|' ) {
+ args.addElement( s.toString() );
+ s = new StringBuffer();
+ }
+ else
+ s.append( c );
+ }
+ if( s.length() != 0 ) args.addElement( s.toString() );
- public boolean moreData() {
- return res_code/100 == MORE_DATA/100;
- }
+ }
+
+ public boolean expressMessage() {
+ return expressmsg;
+ }
- public boolean sendListing() {
- return res_code/100 == SEND_LISTING/100;
- }
+ public boolean listingFollows() {
+ return res_code/100 == LISTING_FOLLOWS/100;
+ }
- public boolean error() {
- return res_code/100 == ERROR/100;
- }
+ public boolean ok() {
+ return res_code/100 == OK/100;
+ }
- public boolean binaryFollows() {
- return res_code/100 == BINARY_FOLLOWS/100;
- }
+ public boolean moreData() {
+ return res_code/100 == MORE_DATA/100;
+ }
- public boolean sendBinary() {
- return res_code/100 == SEND_BINARY/100;
- }
+ public boolean sendListing() {
+ return res_code/100 == SEND_LISTING/100;
+ }
- public boolean startChatMode() {
- return res_code/100 == START_CHAT_MODE/100;
- }
+ public boolean error() {
+ return res_code/100 == ERROR/100;
+ }
- public boolean addData( String s ) {
- if( s.equals( "000" ) )
- return false;
+ public boolean binaryFollows() {
+ return res_code/100 == BINARY_FOLLOWS/100;
+ }
- if( listing == null ) listing = new Vector();
- listing.addElement( s );
- return true;
- }
+ public boolean sendBinary() {
+ return res_code/100 == SEND_BINARY/100;
+ }
- public String getLine( int i ) {
- if( listing == null ) return null;
+ public boolean startChatMode() {
+ return res_code/100 == START_CHAT_MODE/100;
+ }
- if( (i<0) || (i>=listing.size()) ) return null;
+ public boolean addData( String s ) {
+ if( s.equals( "000" ) )
+ return false;
- return (String)listing.elementAt( i );
- }
+ if( listing == null ) listing = new Vector();
+ listing.addElement( s );
+ return true;
+ }
- public String getData() {
- if( data != null ) return data;
+ public String getLine( int i ) {
+ if( listing == null ) return null;
- StringBuffer s = new StringBuffer();
+ if( (i<0) || (i>=listing.size()) ) return null;
- for( Enumeration e=listing.elements(); e.hasMoreElements(); ) {
- s.append( (String)e.nextElement() );
- s.append( "\n" );
+ return (String)listing.elementAt( i );
}
- data = s.toString();
+ public String getData() {
+ if( data != null ) return data;
- return data;
- }
+ StringBuffer s = new StringBuffer();
+
+ for( Enumeration e=listing.elements(); e.hasMoreElements(); ) {
+ s.append( (String)e.nextElement() );
+ s.append( "\n" );
+ }
+
+ data = s.toString();
+
+ return data;
+ }
- public String getArg( int i ) {
- if( args == null ) return "";
+ public String getArg( int i ) {
+ if( args == null ) return "";
- if( (i<0) || (i>=args.size()) ) return "";
+ if( (i<0) || (i>=args.size()) ) return "";
- return (String)args.elementAt( i );
- }
+ return (String)args.elementAt( i );
+ }
}
}
public void lostNetwork( String reason ) {
+ theNet.done = true;
cg.errMsg( reason );
cg.showHostBrowser();
}
cg.mp.rooms.addToFloor( rm );
}
- System.out.println( "Going to room: " + rm.name );
rm.setNew( false );
roomInfo ri = new roomInfo( rm, r );
} } );
}
+ public void zapRoom( final roomInfo ri ) {
+ networkEvent( "FORG " + ri.name, new CallBack() {
+ public void run( citReply r ) {
+ if( r.ok() ) {
+ enterRoom( rooms.forgotRoom( ri ) );
+ cg.mp.setFloor( rooms.getFloor() );
+ } } } );
+ }
+
public void logoff() {
/* close windows */
if( rf != null )
pp.addRight( room = new JTextField(10) );
room.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) {
- pass.requestFocus();
+ if( pass != null )
+ pass.requestFocus();
+ else
+ enterRoom();
} } );
if( def != null ) {
import java.util.*;
public class floor {
- String name, num;
- int number, ref_count;
- SortedVector rooms;
+ String name, num;
+ int number, ref_count;
+ SortedVector rooms;
- public floor( String l ) {
- rooms = new SortedVector( new roomCmp() );
+ public floor( String l ) {
+ rooms = new SortedVector( new roomCmp() );
- int i = l.indexOf( '|' );
- num = l.substring( 0, i );
- number = citadel.atoi( num );
+ int i = l.indexOf( '|' );
+ num = l.substring( 0, i );
+ number = citadel.atoi( num );
- int j = l.indexOf( '|', ++i );
- name = l.substring( i, j );
+ int j = l.indexOf( '|', ++i );
+ name = l.substring( i, j );
- ref_count = citadel.atoi( l.substring( j+1 ) );
+ ref_count = citadel.atoi( l.substring( j+1 ) );
- /* System.out.println( "floor name: " + name );
- System.out.println( "number : " + number );
- System.out.println( "ref_count : " + ref_count );*/
- }
+ /* System.out.println( "floor name: " + name );
+ System.out.println( "number : " + number );
+ System.out.println( "ref_count : " + ref_count );*/
+ }
- public void addRoom( room r ) {
- /* System.out.println( "adding " + r.name() + " to " + name ); */
- rooms.addElement( r );
- }
+ public void addRoom( room r ) {
+ /* System.out.println( "adding " + r.name() + " to " + name ); */
+ rooms.addElement( r );
+ }
- public String num() {
- return num;
- }
+ public String num() {
+ return num;
+ }
- public int number() {
- return number;
- }
+ public int number() {
+ return number;
+ }
- public String name() {
- return name;
- }
+ public String name() {
+ return name;
+ }
}
-
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
JPanel p = new JPanel();
p.setLayout( new BorderLayout() );
- p.setBorder( BorderFactory.createTitledBorder(
- BorderFactory.createEtchedBorder(), "Cmds" ) );
+ /* p.setBorder( BorderFactory.createTitledBorder(
+ BorderFactory.createEtchedBorder(), "Cmds" ) ); */
VertPanel vp = new VertPanel();
p.add( "Center", vp );
}
}
}
-
-
JPanel p = new JPanel();
p.setLayout( new BorderLayout() );
- p.setBorder( BorderFactory.createTitledBorder(
- BorderFactory.createEtchedBorder(), "Cmds" ) );
+ /* p.setBorder( BorderFactory.createTitledBorder(
+ BorderFactory.createEtchedBorder(), "Cmds" ) ); */
VertPanel vp = new VertPanel();
p.add( "Center", vp );
vp.add( b = new JButton( "Read Info" ) );
b.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) {
- // new roomInfoWindow( ri );
+ new roomInfoWindow( ri );
} } );
- b.setEnabled( false );
vp.add( b = new JButton( "Zap Room" ) );
b.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) {
- System.out.println( "Zap room" );
+ if( JOptionPane.showConfirmDialog( null, "Zap " + ri.name + "?" ) == 0 )
+ citadel.me.zapRoom( ri );
} } );
- b.setEnabled( false );
-
- jcb = new JComboBox();
+ jcb = new JComboBox();
jcb.addItem( "Read New" );
jcb.addItem( "Read All" );
jcb.addItem( "Last 5" );
setTitle( title );
cdLayout.show( c, "Messages" );
mp.refresh( ri );
+ if( ri.info != 0)
+ new roomInfoWindow( ri );
}
public void showRoom() {
floor = citadel.atoi( r.getArg( 10 ) );
}
}
+
+
+
import java.util.*;
public class roomMap {
- Vector f_list;
- Hashtable floors, rooms;
+ Vector f_list;
+ Hashtable floors, rooms;
- floor cur_floor;
- mainPanel mp;
+ floor cur_floor;
+ mainPanel mp;
- public roomMap( mainPanel mp ) {
- f_list = new Vector();
- floors = new Hashtable();
- rooms = new Hashtable();
- this.mp = mp;
- }
+ public roomMap( mainPanel mp ) {
+ f_list = new Vector();
+ floors = new Hashtable();
+ rooms = new Hashtable();
+ this.mp = mp;
+ }
- public void floors( citReply r ) {
- int i = 0;
- String line;
+ public void floors( citReply r ) {
+ int i = 0;
+ String line;
- floors = new Hashtable();
+ floors = new Hashtable();
- while( (line = r.getLine( i++ ) ) != null ) {
- floor f = new floor( line );
- floors.put( f.num, f );
- floors.put( f.name, f );
- f_list.addElement( f );
+ while( (line = r.getLine( i++ ) ) != null ) {
+ floor f = new floor( line );
+ floors.put( f.num, f );
+ floors.put( f.name, f );
+ f_list.addElement( f );
+ }
}
- }
-
- public void new_rooms( citReply rep ) {
- int i = 0;
- String line;
-
- while( (line = rep.getLine( i++ ) ) != null ) {
- room r, rr = new room( line );
- r = (room)rooms.get( rr.name() );
- if( r == null ) {
- rr.setNew();
- rooms.put( rr.name, rr );
- addToFloor( rr );
- } else
- r.setNew();
+
+ public void new_rooms( citReply rep ) {
+ int i = 0;
+ String line;
+
+ while( (line = rep.getLine( i++ ) ) != null ) {
+ room r, rr = new room( line );
+ r = (room)rooms.get( rr.name() );
+ if( r == null ) {
+ rr.setNew();
+ rooms.put( rr.name, rr );
+ addToFloor( rr );
+ } else
+ r.setNew();
+ }
}
- }
- public void old_rooms( citReply rep ) {
- int i = 0;
- String line;
+ public void old_rooms( citReply rep ) {
+ int i = 0;
+ String line;
- while( (line = rep.getLine( i++ )) != null ) {
- room r = new room( line );
- rooms.put( r.name(), r );
- addToFloor( r );
+ while( (line = rep.getLine( i++ )) != null ) {
+ room r = new room( line );
+ rooms.put( r.name(), r );
+ addToFloor( r );
+ }
}
- }
-
- public void addToFloor( room r ) {
- floor f = (floor)floors.get( r.fname );
- if( f != null )
- f.addRoom( r );
- }
-
- public floor nextFloor() {
- int c = f_list.indexOf( cur_floor );
- c++;
-
- try {
- cur_floor = (floor)f_list.elementAt( c );
- } catch( Exception e ) {
- cur_floor = (floor)f_list.firstElement();
+
+ public void addToFloor( room r ) {
+ floor f = (floor)floors.get( r.fname );
+ if( f != null )
+ f.addRoom( r );
}
- setFloor( cur_floor );
- return cur_floor;
- }
+ public floor nextFloor() {
+ int c = f_list.indexOf( cur_floor );
+ c++;
+
+ try {
+ cur_floor = (floor)f_list.elementAt( c );
+ } catch( Exception e ) {
+ cur_floor = (floor)f_list.firstElement();
+ }
+
+ setFloor( cur_floor );
+ return cur_floor;
+ }
- public floor getFloor() {
- if( cur_floor == null ) cur_floor = (floor)f_list.firstElement();
-
- return cur_floor;
- }
-
- public floor getFloor( String name ) {
- return (floor)floors.get( name );
- }
-
- public floor getFloor( room rm ) {
- return getFloor( rm.fname );
- }
-
- public void setFloor( floor f ) {
- cur_floor = f;
- mp.setFloor( f );
- mp.updateLists( f.name() );
- }
-
- public room nextNewRoom() {
- floor c = getFloor();
-
- do {
- for( Enumeration e = getFloor().rooms.elements(); e.hasMoreElements(); ) {
- room r = (room)e.nextElement();
- if( r.hasNew() ) return r;
- }
- nextFloor();
- } while( c != getFloor() );
-
- System.out.println( "No more new rooms... refreshing list" );
-
- citadel.me.networkEvent( "LKRN", new CallBack() {
- public void run( citReply r ) {
- new_rooms( r );
- room rm = getRoom( "Lobby" );
- setFloor( getFloor( rm ) );
+ public floor getFloor() {
+ if( cur_floor == null ) cur_floor = (floor)f_list.firstElement();
+
+ return cur_floor;
+ }
+
+ public floor getFloor( String name ) {
+ return (floor)floors.get( name );
+ }
+
+ public floor getFloor( room rm ) {
+ return getFloor( rm.fname );
+ }
+
+ public void setFloor( floor f ) {
+ cur_floor = f;
+ mp.setFloor( f );
+ mp.updateLists( f.name() );
+ }
+
+ public room nextNewRoom() {
+ floor c = getFloor();
+
+ do {
+ for( Enumeration e = getFloor().rooms.elements(); e.hasMoreElements(); ) {
+ room r = (room)e.nextElement();
+ if( r.hasNew() ) return r;
+ }
+ nextFloor();
+ } while( c != getFloor() );
+
+ System.out.println( "No more new rooms... refreshing list" );
+
+ citadel.me.networkEvent( "LKRN", new CallBack() {
+ public void run( citReply r ) {
+ new_rooms( r );
+ room rm = getRoom( "Lobby" );
+ setFloor( getFloor( rm ) );
- } } );
+ } } );
+
+ room r = getRoom( "Lobby" );
+ setFloor( getFloor( r ) );
- room r = getRoom( "Lobby" );
- setFloor( getFloor( r ) );
+ return r;
+ }
- return r;
- }
+ public room getRoom( String name ) {
+ return (room)rooms.get(name);
+ }
- public room getRoom( String name ) {
- return (room)rooms.get(name);
- }
+ public room forgotRoom( roomInfo ri ) {
+ room r = (room)rooms.remove( ri.name );
+ if( r == null ) return nextNewRoom();
+ floor f = getFloor( ri.rm );
+ if( f == null ) return nextNewRoom();
+ f.rooms.removeElement( ri.rm );
+ return nextNewRoom();
+ }
}
+
+
+