-mod: 28 Jul 1999
+mod: 29 Jul 1999
Basic:
- Connect to server and login (connects, gets "hello" and throws up window)
"main"
- Splits rooms up into new and no-new
- * no floor support yet.
+ * limited floor support (shows in message panel)
* doesn't sort the room names, even though there's "no pressing reason not to"
- Go to next room with messages
public boolean handleEvent( Event e ) {
if( e.id == Event.WINDOW_DESTROY ) {
if( citadel.me.theNet != null )
- citadel.me.theNet.println( "QUIT" );
+ citadel.me.getReply( "QUIT" );
System.out.println( "Bye bye!" );
System.exit( 0 );
}
add( "Enter", ep = new enterPanel() );
add( "Logoff", offP = new logoffPanel() );
- citadel.me.cp = this;
+ citadel.me.setCitPanel( this );
login();
}
net theNet;
server serverInfo;
user theUser;
- citPanel cp;
+ private citPanel cp;
boolean floors;
whoWindow wo;
+ roomMap rooms;
public static citadel me;
citFrame cf = new citFrame();
}
+ public static int atoi( String s ) {
+ try {
+ return Integer.parseInt( s );
+ } catch( Exception e ) {
+ return 0;
+ }
+ }
+
public citadel( boolean applet ) {
me = this;
this.applet = false;
theUser = null;
wo = null;
+ rooms = new roomMap();
+ }
+
+ public void setCitPanel( citPanel cp ) {
+ this.cp = cp;
}
public void lostNetwork( String reason ) {
}
public String getSystemMessage( String name ) {
- citReply rep = theNet.getReply( "MESG " + name );
+ citReply rep = getReply( "MESG " + name );
if( rep.listingFollows() )
return rep.getData();
else
}
public citReply getReply( String s ) {
+ return getReply( s, (String)null );
+ }
+
+ public citReply getReply( String s, String d ) {
if( theNet == null ) return null;
- return theNet.getReply( s );
+ return theNet.getReply( s,d );
}
public void enterRoom( String room ) {
enterRoom( room, null );
}
+ public void gotoRoom( ) {
+ gotoRoom( null, false );
+ }
+
+ public void gotoRoom( String name, boolean flag ) {
+ /* TODO: prompt for room name */
+ System.out.println( "This is where I would ask you for the room's name" );
+ }
+
public void enterRoom( String room, String pass ) {
String cmd = "GOTO " + room;
if( pass != null )
cmd = cmd + " " + pass;
citReply r=getReply( cmd );
if( r.ok() ) {
- cp.mp.visited( room );
+ rooms.visited( room );
cp.enterRoom( r );
} else if( r.res_code == 540 ) /* ERROR+PASSWORD_REQUIRED */
new passwordWindow( room );
}
+ public void showMsgPane() {
+ cp.deck.show( cp, "Message" );
+ }
+
+ public void login() {
+ rooms.loadFloorInfo();
+ cp.login();
+ }
+
+ public void mainMenu() {
+ cp.mainMenu();
+ }
+
public void enterMsg( String room ) {
cp.enterMsg( room );
}
public void nextNewRoom() {
- enterRoom( cp.mp.nextNewRoom() );
+ enterRoom( rooms.nextNewRoom() );
}
public void expressMsg() {
if( mail ) cmd = cmd + rec;
cmd = cmd + "|0|0|0";
- citReply r = getReply( cmd );
- if( r.sendListing() ) {
- theNet.println( body );
- theNet.println( "000" );
- }
+ citReply r = getReply( cmd, body );
+ if( r.error() )
+ error( r );
}
public void logoff() {
cp.logoff(null);
- theNet.println( "quit" );
+ getReply( "QUIT" );
}
public void who_online() {
public void page_user( String who ) {
new pageWindow( who );
}
+
+ public void error( citReply r ) {
+ System.out.println( r.line );
+ }
}
public boolean action( Event e, Object o ) {
if( e.target == ok ) {
citadel.me.sendMessage( msg.getText(), who.getText(), mail );
- citadel.me.cp.deck.show( citadel.me.cp, "Message" ); // Umm... this is bad
+ citadel.me.showMsgPane();
} else if( e.target == cancel ) {
- citadel.me.cp.deck.show( citadel.me.cp, "Message" ); // Umm... this is bad } else if( e.taget == who ) {
+ citadel.me.showMsgPane();
msg.requestFocus();
}
return super.action( e, o );
citadel.me.host = host.getText();
citadel.me.openConnection( citadel.me.host );
- citadel.me.cp.login();
+ citadel.me.login();
} else if ( e.target == close ) {
System.out.println( "Thanks!" );
System.exit( 0 );
import java.awt.*;
public class mainPanel extends Panel {
- List new_msgs, seen;
+ List newL, oldL;
Button next_room, goto_room;
Button who_is_online, page_user;
Button logout;
NamedPanel np = new NamedPanel( "New Messages" );
np.setLayout( new BorderLayout() );
- np.add( "Center", new_msgs = new List() );
+ np.add( "Center", newL = new List() );
p.add( np );
np = new NamedPanel( "Seen Messages" );
np.setLayout( new BorderLayout() );
- np.add( "Center", seen = new List() );
+ np.add( "Center", oldL = new List() );
p.add( np );
add( "Center", p );
p = new Panel();
p.add( logout = new Button( "Logout" ) );
add( "South", p );
+
+ citadel.me.rooms.setList( newL, oldL );
}
public boolean action( Event e, Object o ) {
- if( (e.target == new_msgs) || (e.target == seen) || (e.target == goto_room)) {
+ if( (e.target == newL) || (e.target == oldL) || (e.target == goto_room)) {
String room = getRoom();
if( room != null )
citadel.me.enterRoom( room );
citadel.me.page_user();
} else if (e.target == next_room ) {
citadel.me.nextNewRoom();
+ } else if( e.target == goto_room ) {
+ citadel.me.gotoRoom( getRoom(), true );
} else if( e.target == logout ) {
citadel.me.logoff();
} else {
public boolean handleEvent( Event e ) {
if( e.id == Event.LIST_SELECT ) {
- if( e.target == new_msgs ) {
- int i = seen.getSelectedIndex();
+ if( e.target == newL ) {
+ int i = oldL.getSelectedIndex();
if( i != -1 )
- seen.deselect( i );
+ oldL.deselect( i );
} else {
- int i = new_msgs.getSelectedIndex();
+ int i = newL.getSelectedIndex();
if( i != -1 )
- new_msgs.deselect( i );
+ newL.deselect( i );
}
}
return super.handleEvent( e );
}
public void refresh() {
- new_msgs.clear();
- parseRooms( new_msgs, citadel.me.getReply( "LKRN" ) );
-
- seen.clear();
- parseRooms( seen, citadel.me.getReply( "LKRO" ) );
- }
-
- public void parseRooms( List l, citReply r ) {
- int i=0;
- String s;
-
- while( (s = r.getLine( i++) ) != null ) {
- int j = s.indexOf( '|' );
- if( j != -1 )
- l.addItem( s.substring( 0, j ) );
- else
- l.addItem( s );
- }
+ citadel.me.rooms.refresh();
}
public String getRoom() {
- String s = new_msgs.getSelectedItem();
- if( s == null ) s = seen.getSelectedItem();
+ String s = newL.getSelectedItem();
+ if( s == null ) s = oldL.getSelectedItem();
return s;
}
- public String nextNewRoom() {
- if( new_msgs.countItems() == 0 ) return "Lobby";
-
- return new_msgs.getItem( 0 );
- }
-
- public void visited( String room ) {
- for( int i = 0; i < new_msgs.countItems(); i++ ) {
- if( room.equals( new_msgs.getItem( i ) ) ) {
- new_msgs.delItem( i );
- seen.addItem( room );
- }
- }
- }
}
public class messagePanel extends Panel {
Choice reading;
Button who_is_online, room_info;
- Button next_room, page_user;
+ Button next_room, goto_room, page_user;
Button next_msg, prev_msg, enter_msg, back;
TextField msgInfo;
TextArea theMsg;
public messagePanel() {
setLayout( new BorderLayout() );
- Panel p = new Panel();
- p.add( reading = new Choice() );
+ VertPanel vp = new VertPanel();
+ vp.add( reading = new Choice() );
reading.addItem( "Read New" );
reading.addItem( "Read All" );
reading.addItem( "Last 5" );
reading.select( 0 );
- // p.add( who_is_online = new Button( "Who is Online" ) );
- p.add( room_info = new Button( "Room Info" ) );
- p.add( next_room = new Button( "Next Room" ) );
- p.add( page_user = new Button( "Page User" ) );
- add( "North", p );
+ vp.add( next_msg = new Button( "Next Message" ) );
+ vp.add( prev_msg = new Button( "Prev Message" ) );
+ vp.add( enter_msg = new Button( "Enter Message" ) );
+ vp.add( next_room = new Button( "Next Room" ) );
+ vp.add( goto_room = new Button( "Goto Room" ) );
+ vp.add( room_info = new Button( "Room Info" ) );
+ vp.add( who_is_online = new Button( "Who is Online" ) );
+ vp.add( page_user = new Button( "Page User" ) );
+ vp.add( back = new Button( "Back" ) );
+
+ add( "West", vp );
np = new NamedPanel( "Message" );
np.setLayout( new BorderLayout() );
np.add( "Center", theMsg = new TextArea() );
add( "Center", np );
- p = new Panel();
- p.add( next_msg = new Button( "Next Message" ) );
- p.add( prev_msg = new Button( "Prev Message" ) );
- p.add( enter_msg = new Button( "Enter Message" ) );
- p.add( back = new Button( "Back" ) );
- add( "South", p );
+ /* Panel p = new Panel();
+ add( "South", p );*/
}
public boolean action( Event e, Object o ) {
citadel.me.enterMsg( name );
} else if( e.target == next_room ) {
citadel.me.nextNewRoom();
+ } else if( e.target == goto_room ) {
+ citadel.me.gotoRoom();
} else if( e.target == back ) {
- citadel.me.cp.mainMenu();
+ citadel.me.mainMenu();
}
return super.action( e, o );
}
public void refresh( citReply r ) {
name = r.getArg( 0 );
- np.setLabel( name );
- total = atoi( r.getArg( 1 ) );
- unread = atoi( r.getArg( 2 ) );
- info = atoi( r.getArg( 3 ) );
- flags = atoi( r.getArg( 4 ) );
- highest = atoi( r.getArg( 5 ) );
- highest_read = atoi( r.getArg( 6 ) );
- mail = atoi( r.getArg( 7 ) ) != 0;
- aide = atoi( r.getArg( 8 ) ) != 0;
- mail_num = atoi( r.getArg( 9 ) );
- floor = atoi( r.getArg( 10 ) );
+ np.setLabel( name + " (" + citadel.me.rooms.getRoomsFloorName( name )+")" );
+ total = citadel.atoi( r.getArg( 1 ) );
+ unread = citadel.atoi( r.getArg( 2 ) );
+ info = citadel.atoi( r.getArg( 3 ) );
+ flags = citadel.atoi( r.getArg( 4 ) );
+ highest = citadel.atoi( r.getArg( 5 ) );
+ highest_read = citadel.atoi( r.getArg( 6 ) );
+ mail = citadel.atoi( r.getArg( 7 ) ) != 0;
+ aide = citadel.atoi( r.getArg( 8 ) ) != 0;
+ mail_num = citadel.atoi( r.getArg( 9 ) );
+ floor = citadel.atoi( r.getArg( 10 ) );
msgInfo.setText( "" );
theMsg.setText( "" );
getMsgsPtrs();
}
- public int atoi( String s ) {
- try {
- return Integer.parseInt( s );
- } catch( Exception e ) {
- return 0;
- }
- }
-
public void getMsgsPtrs() {
msgs = null;
String which = "new";
msgInfo.setText( sum );
theMsg.setText( r.getData() ); /* this relies on the fact that we've removed the header lines above. probably a messy way to deal with references. */
- int n = atoi( num );
+ int n = citadel.atoi( num );
if( n > highest_read ) {
highest_read = n;
citadel.me.getReply( "SLRP " + num );
theServer = null;
}
- public void println( String s ) {
+ private void println( String s ) {
System.out.println( ">" + s );
try {
if( theServer != null )
}
}
- public String readLine( ) {
+ private String readLine( ) {
try {
if( theServer != null ) {
String s = in.readLine();
}
public citReply getReply() {
- return getReply( (String)null );
+ return getReply( (String)null, (String)null );
}
public citReply getReply( String cmd ) {
+ return getReply( cmd, (String)null );
+ }
+
+ public citReply getReply( String cmd, String data ) {
if( cmd != null ) println( cmd );
citReply r = new citReply( readLine() );
while( r.addData( readLine() ) ) ;
}
+ if( r.sendListing() ) {
+ if( data != null )
+ println( data );
+ println( "000" );
+ }
+
if( r.expressMessage() )
citadel.me.expressMsg();
String m = msg.getText();
if( m.length() > 0 ) {
if( multi_line ) {
- citReply r = citadel.me.getReply( "SEXP " + user + "|-" );
- if( r.sendListing() ) {
- citadel.me.theNet.println( m );
- citadel.me.theNet.println( "" );
- citadel.me.theNet.println( "000" );
- }
+ citReply r = citadel.me.getReply( "SEXP " + user + "|-", m + "\n" );
+ if( r.error() )
+ citadel.me.error( r );
} else
citadel.me.getReply( "SEXP " + user + "|" + m );
}
public boolean action( Event e, Object o ) {
if( (e.target == text) || (e.target instanceof Button) ) {
String s = text.getText();
- citReply r = citadel.me.getReply( "GOTO " + room + " " + s );
- if( r.ok() ) {
- citadel.me.cp.mp.visited( room );
- citadel.me.cp.enterRoom( r );
- dispose();
- } else {
- dispose();
- new passwordWindow( room );
- }
+ dispose();
+ citadel.me.enterRoom( room, s );
}
return super.action( e, o );
}
String blurb;
public server( citReply r ) {
- session_id = atoi( r.getLine( 0 ) );
+ session_id = citadel.atoi( r.getLine( 0 ) );
node_name = r.getLine( 1 );
human_name = r.getLine( 2 );
fqdn = r.getLine( 3 );
server_name = r.getLine( 4 );
- rev_level = atoi( r.getLine( 5 ) );
+ rev_level = citadel.atoi( r.getLine( 5 ) );
geo_local = r.getLine( 6 );
sysadmin = r.getLine( 7 );
- server_type = atoi( r.getLine( 8 ) );
+ server_type = citadel.atoi( r.getLine( 8 ) );
page_prompt = r.getLine( 9 );
- floor_flag = atoi( r.getLine( 10 ) );
- page_level = atoi( r.getLine( 11 ) );
+ floor_flag = citadel.atoi( r.getLine( 10 ) );
+ page_level = citadel.atoi( r.getLine( 11 ) );
blurb = server_name + " " + human_name + " " + geo_local;
System.out.println( blurb );
}
-
- public int atoi( String s ) {
- if( s == null ) return 0;
-
- try {
- return Integer.parseInt( s );
- } catch( NumberFormatException nfe ) {};
- return 0;
- }
}
public user( citReply r ) {
username = r.getArg( 0 );
- access = atoi( r.getArg( 1 ) );
- call = atoi( r.getArg( 2 ) );
- msg = atoi( r.getArg( 3 ) );
- flags = atoi( r.getArg( 4 ) );
- num = atoi( r.getArg( 5 ) );
+ access = citadel.atoi( r.getArg( 1 ) );
+ call = citadel.atoi( r.getArg( 2 ) );
+ msg = citadel.atoi( r.getArg( 3 ) );
+ flags = citadel.atoi( r.getArg( 4 ) );
+ num = citadel.atoi( r.getArg( 5 ) );
}
public boolean floors() {
return (flags & FLOORS)==FLOORS;
}
-
- public int atoi( String s ) {
- if( s == null ) return 0;
-
- try {
- return Integer.parseInt( s );
- } catch( NumberFormatException nfe ) {};
- return 0;
- }
}