?? messageprocessor.java
字號:
/*
* MessageProcessor.java
*
* Copyright (C) 2000 Jason M. Hanley
* Released under the GNU General Public License (GPL)
* See license.txt for additional information.
*
* Created on July 28, 2000, 11:40 PM
*/
package fate.client;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import fate.messages.*;
import fate.network.*;
import fate.util.*;
import fate.server.*;
import fate.world.*;
/**
* Thread to handle and process incoming messages for the client.
*
* @author preylude@s3m.com
* @version 0.1.0
*/
public class MessageProcessor extends Thread {
static final int DELAY_TIME = 100;
ClientConnection connection;
ConsoleFrame console;
/** Creates new MessageProcessor */
public MessageProcessor( ClientConnection connection, ConsoleFrame console ) {
this.connection = connection;
this.console = console;
}
/** Process incoming messages from the server */
public void run() {
try {
Debug.trace( "MessageProcessor initialzed and entering loop" );
while (true) {
// Loop while there are incoming messages
while ( connection.messagesAvailable() ) {
Object msgIn = connection.nextMessage();
Class c = msgIn.getClass();
Debug.trace( "MessageProcessor read msg: " + c.getName() );
// Handle chat messages
if ( c.getName().endsWith( "ChatMessage" ) ) {
console.chatPanel.onReceiveChatMessage( (ChatMessage) msgIn );
}
// Handle get player messages
else if ( c.getName().endsWith( "GetPlayerMessage" ) ) {
Player player = ((GetPlayerMessage)msgIn).player;
console.setPlayer( player );
SwitchMainViewMessage msgToSend = new SwitchMainViewMessage();
msgToSend.viewType = PlayerState.MAIN_VIEW_SOLARSYSTEM;
Iterator iter = player.mapShips.values().iterator();
Ship ship = (Ship) iter.next();
if (ship != null) {
Planetoid planetoid = (Planetoid) ship.parent;
msgToSend.idPlanetoid = planetoid.id;
SolarSystem solarSystem = (SolarSystem) planetoid.parent;
msgToSend.idSolarSystem = solarSystem.id;
Galaxy galaxy = (Galaxy) solarSystem.parent;
if (galaxy != null)
msgToSend.idGalaxy = galaxy.id;
else
Debug.trace( "Error: galaxy is null" );
}
else
Debug.trace( "Error: ship is null" );
connection.sendMessage( msgToSend );
}
// Handle solar system view messages
else if ( c.getName().endsWith( "SolarSystemViewMessage" ) ) {
SolarSystemViewMessage msg = (SolarSystemViewMessage) msgIn;
OrbitingBody object = (OrbitingBody) msg.planetList.iterator().next();
Debug.trace( "First planet: " + object.name + ", " + object.id +
", pos:" + object.position );
console.mainViewPanel.updateObjects( msg.planetList );
}
// Handle ChangeLoginMessage messages
else if ( c.getName().endsWith( "ChangeLoginMessage" ) ) {
ChangeLoginMessage msg = (ChangeLoginMessage) msgIn;
if( msg.bAccepted == true ) {
console.parent.editUsername.setText( msg.username );
console.parent.editPassword.setText( msg.password );
JOptionPane.showMessageDialog( null, "The server reports that your login " +
"and/or password has been sucessfully changed.\nThe new values have been " +
"automatically entered on the main login dialog and will be saved when you exit.",
"Login/Password changed", JOptionPane.ERROR_MESSAGE);
} else {
JOptionPane.showMessageDialog( null, "Error: Server did not accept login change.\n" +
"It is possible that the username you requested is already in use.\n" +
"Please try again.",
"Error", JOptionPane.ERROR_MESSAGE);
}
}
}
sleep( DELAY_TIME );
}
} catch ( Exception e ) {
Debug.trace( "MessageProcessor.run() Exception " + e.getMessage() );
e.printStackTrace();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -