1 import javax.swing.JFrame;
5 public final static String NAME="Shaggy", VERSION="0.1";
6 public static citadel me;
19 whoOnlineWindow wo = null;
21 public static void main( String args[] ) {
25 public static int atoi( String s ) {
26 if( s == null ) return 0;
28 return Integer.parseInt( s );
29 } catch( NumberFormatException nfe ) {
40 windows = new Vector();
43 public void showHostBrowser() {
47 public void setServer( String server, String port ) {
50 setServer( server, p );
53 public void setServer( String server, int port ) {
57 Thread t = new Thread( theNet );
61 public void setServerInfo( server s ) {
65 public void showLoginPanel() {
69 public void showLoginPanel( String user, String pass ) {
70 cg.showLoginPanel( user, pass );
73 public void showMainPanel() {
77 public void expressMsg() {
78 networkEvent( "GEXP", new CallBack() {
79 public void run( citReply r ) {
82 if( atoi( r.getArg( 0 ) ) != 0 )
87 public void gotoRoom( String name ) {
88 System.out.println( "goto room:" + name );
91 public void lostNetwork( String reason ) {
98 public void warning( String text ) {
102 public void closeFrame() {
104 System.out.println( "Closed the frame." );
108 public void networkEvent( String cmd ) {
109 networkEvent( cmd, null, null );
112 public void networkEvent( String cmd, CallBack cb ) {
113 networkEvent( cmd, null, cb );
116 public void networkEvent( String cmd, String data ) {
117 networkEvent( cmd, data, null );
120 public void networkEvent( String cmd, String data, CallBack cb ) {
121 theNet.append( new MsgCmd( cmd, data, cb ) );
124 public void getServerInfo( CallBack cb ) {
125 networkEvent( "INFO", cb );
128 public void getSystemMessage( String f_name, CallBack cb ) {
129 networkEvent( "MESG " + f_name, cb );
132 public void authenticate( final String user, final String pass ) {
133 networkEvent( "USER " + user, new CallBack() {
134 public void run( citReply r ) {
136 networkEvent( "PASS "+ pass, new CallBack() {
137 public void run( citReply r ) {
139 warning( "Wrong Password" );
141 citadel.me.setUser( new user( r ) );
145 warning( user + ":No such user" );
151 public void enterRoom() {
152 new enterRoomWindow();
155 public void enterRoom( String s ) {
156 enterRoom( s, null );
159 public void enterRoom( room r ) {
160 enterRoom( r.name, null );
163 public void enterRoom( final String roomName, String pass ) {
164 String cmd = "GOTO " + roomName;
166 cmd = cmd + "|" + pass;
168 networkEvent( cmd, new CallBack() {
169 public void run( citReply r ) {
171 room rm = cg.mp.rooms.getRoom( roomName );
172 if( rm == null ) { /* didn't know about it before */
173 rm = new room( roomName, r.getArg( 10 ) );
174 cg.mp.rooms.rooms.put( roomName, rm );
175 cg.mp.rooms.addToFloor( rm );
180 roomInfo ri = new roomInfo( rm, r );
182 /* check ri.mail and act accordingly */
185 rf = new roomFrame();
188 cg.mp.updateLists( rooms.getFloor().name() ); // hack
189 } else if( r.res_code == 540 ) {
190 new enterRoomWindow( roomName );
195 public void zapRoom( final roomInfo ri ) {
196 networkEvent( "FORG " + ri.name, new CallBack() {
197 public void run( citReply r ) {
199 enterRoom( rooms.forgotRoom( ri ) );
200 cg.mp.setFloor( rooms.getFloor() );
204 public void logoff() {
207 cg.showLogoffPanel();
208 networkEvent( "QUIT", new CallBack() {
209 public void run( citReply r ) {
214 public void cleanup() {
219 for( Enumeration e = windows.elements(); e.hasMoreElements(); ) {
220 JFrame f = (JFrame)e.nextElement();
225 public void setUser( user theUser ) {
226 this.theUser = theUser;
228 networkEvent( "CHEK", new CallBack() {
229 public void run( citReply r ) {
230 int msg = atoi( r.getArg( 0 ) );
236 public void registerWindow( JFrame win ) {
237 windows.addElement( win );
240 public void removeWindow( JFrame win ) {
241 windows.removeElement( win );
244 public boolean floors() {
245 return true; // FIXME