You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(20) |
Jun
(46) |
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
|
Feb
|
Mar
(86) |
Apr
(77) |
May
(21) |
Jun
(11) |
Jul
(16) |
Aug
(3) |
Sep
|
Oct
|
Nov
|
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(48) |
Oct
(1) |
Nov
(4) |
Dec
|
From: Snowdog <sn...@ga...> - 2013-09-16 17:09:51
|
Damn, caught with my hand in the cookie jar again. ;) Hey Mark, I thought everyone had given up on this list long ago. Go ahead and tear out the old dice roller code and replace it with your new stuff. It won't interfere with any of my core coding I've been doing (being as there is no chat code yet) As for generics, yeah I've already been using them in the new code I've done recently. Figured at this point, Java 1.7 is the new baseline for ORPG2. Most of the non-generic collections have been depreciated in favor of the generics anyway. On Sep 13, 2013, at 10:37 PM, Mark Tarrabain <ma...@ly...> wrote: > Snowdog's been busy, it seems. > > Still, it's nice to see some activity here.... I've actually completely > redesigned the dice roller that I wrote here since I was last working on > this... learning from the mistakes I made with this one being far too > generic, and as a result harder to use. The new one I came up with is > actually more powerful, supporting things like adding variable numbers > of dice to a die roll (ie. highest(3d6.more(5..6,1),3) would start by > rolling a d6 and add 1 more die each time a 5 or 6 is rolled, and would > finally take the highest 3 dice from that). > > Should I commit that? It's all within the openrpg2.common.dice package. > > Oh... one more thing... Can we use generics now? Or do we still have > to use the pre-Java6 notation? > > Mark > > ------------------------------------------------------------------------------ > LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99! > 1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint > 2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes > Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/22/13. > http://pubads.g.doubleclick.net/gampad/clk?id=64545871&iu=/4140/ostg.clktrk > _______________________________________________ > Openrpg-v2-dev mailing list > Ope...@li... > https://lists.sourceforge.net/lists/listinfo/openrpg-v2-dev --Snowdog |
From: <sno...@us...> - 2013-09-14 17:50:47
|
Revision: 99 http://sourceforge.net/p/openrpg/svn/99 Author: snowdog_ Date: 2013-09-14 17:50:44 +0000 (Sat, 14 Sep 2013) Log Message: ----------- Fixed bug that was preventing modules from properly registering event interest with the event manager. Modified Paths: -------------- trunk/src/openrpg2/common/core/event/ModuleEventManager.java trunk/src/openrpg2/common/core/group/GroupServerModule.java Modified: trunk/src/openrpg2/common/core/event/ModuleEventManager.java =================================================================== --- trunk/src/openrpg2/common/core/event/ModuleEventManager.java 2013-09-14 17:15:39 UTC (rev 98) +++ trunk/src/openrpg2/common/core/event/ModuleEventManager.java 2013-09-14 17:50:44 UTC (rev 99) @@ -25,6 +25,8 @@ import java.util.Iterator; import java.util.Map; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; import openrpg2.common.module.ModuleEventListener; /** @@ -44,10 +46,12 @@ public class ModuleEventManager { private HashMap<String,HashMap> eventMap = null; + private Logger log; public ModuleEventManager(){ this.eventMap = new HashMap<>(); + log = Logger.getLogger( this.getClass().getName()); } /** @@ -80,7 +84,6 @@ * @param eventId Id of the event to listen for */ public void registerEventListener(ModuleEventListener listener, String moduleName, int eventId){ - //System.out.println("registerEventListener("+listener.toString()+","+moduleName+","+eventId); registerEventSender(moduleName,eventId); HashMap<Integer,ArrayList> events; ArrayList<ModuleEventListener> watchers; @@ -91,13 +94,16 @@ if((watchers != null)&&( !watchers.contains(listener))){ watchers.add(listener); + }else{ + watchers = new ArrayList<>(); + watchers.add(listener); + events.put(eventId, watchers); } }else{ watchers = new ArrayList<>(); watchers.add(listener); events.put(eventId, watchers); } - } /** @@ -108,7 +114,9 @@ */ public void sendEvent(ORPGEvent e){ ArrayList<ModuleEventListener> watchers = getListeners(e.sourceModuleName,e.id); - if( watchers == null){ return; }//nothing to do + if( watchers == null){ + this.log.log(Level.FINER, "Event has no listeners: {0}", e.toString()); + return; }//nothing to do Iterator<ModuleEventListener> it = watchers.iterator(); while(it.hasNext()) { @@ -119,7 +127,7 @@ } private ArrayList<ModuleEventListener> getListeners(String m, int i){ - HashMap<Integer,ArrayList> events = null; + HashMap<Integer,ArrayList> events; ArrayList<ModuleEventListener> watchers = new ArrayList<>(); if(this.eventMap.containsKey(m)){ events = this.eventMap.get(m); Modified: trunk/src/openrpg2/common/core/group/GroupServerModule.java =================================================================== --- trunk/src/openrpg2/common/core/group/GroupServerModule.java 2013-09-14 17:15:39 UTC (rev 98) +++ trunk/src/openrpg2/common/core/group/GroupServerModule.java 2013-09-14 17:50:44 UTC (rev 99) @@ -57,8 +57,8 @@ protected void doRegistration(){ modCom.registerMessageType(ORPGConstants.TYPE_GROUP, this); modCom.registerEventSender(this, GroupServerModule.EVENT_GROUPDATA_CHANGED); - modCom.registerEventInterest(this, "NetworkServerModule", NetworkServerModule.EVENT_CLIENT_JOIN); - modCom.registerEventInterest(this, "NetworkServerModule", NetworkServerModule.EVENT_CLIENT_DISCONNECT); + modCom.registerEventInterest(this, NetworkServerModule.class.getSimpleName(), NetworkServerModule.EVENT_CLIENT_JOIN); + modCom.registerEventInterest(this, NetworkServerModule.class.getSimpleName(), NetworkServerModule.EVENT_CLIENT_DISCONNECT); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sno...@us...> - 2013-09-14 17:15:42
|
Revision: 98 http://sourceforge.net/p/openrpg/svn/98 Author: snowdog_ Date: 2013-09-14 17:15:39 +0000 (Sat, 14 Sep 2013) Log Message: ----------- Removed typo in static string... replaced with more 'correct' class getSimpleName call. Modified Paths: -------------- trunk/src/openrpg2/server/core/modules/clientlist/ClientList.java Modified: trunk/src/openrpg2/server/core/modules/clientlist/ClientList.java =================================================================== --- trunk/src/openrpg2/server/core/modules/clientlist/ClientList.java 2013-09-14 16:16:12 UTC (rev 97) +++ trunk/src/openrpg2/server/core/modules/clientlist/ClientList.java 2013-09-14 17:15:39 UTC (rev 98) @@ -69,7 +69,7 @@ @Override protected void doRegistration() { this.modCom.registerGUIComponent("Client List", panel); - this.modCom.registerEventInterest(this, "GroupSeverModule", GroupServerModule.EVENT_GROUPDATA_CHANGED); + this.modCom.registerEventInterest(this, GroupServerModule.class.getSimpleName(), GroupServerModule.EVENT_GROUPDATA_CHANGED); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sno...@us...> - 2013-09-14 16:16:15
|
Revision: 97 http://sourceforge.net/p/openrpg/svn/97 Author: snowdog_ Date: 2013-09-14 16:16:12 +0000 (Sat, 14 Sep 2013) Log Message: ----------- Removed outdated code in BaseModule. Java 1.7 constructs now required by code to compile so java 1.4 workarounds are unneeded now. Modified Paths: -------------- trunk/src/openrpg2/common/module/BaseModule.java Modified: trunk/src/openrpg2/common/module/BaseModule.java =================================================================== --- trunk/src/openrpg2/common/module/BaseModule.java 2013-09-14 15:49:36 UTC (rev 96) +++ trunk/src/openrpg2/common/module/BaseModule.java 2013-09-14 16:16:12 UTC (rev 97) @@ -64,27 +64,11 @@ /** Creates a new instance of BaseModule */ public BaseModule(){ - this.setModuleName(getModuleSimpleName(this.getClass().getName())); + this.setModuleName(this.getClass().getSimpleName()); log = Logger.getLogger( this.getClass().getName()); } /** - * This method works around an Java versioning issue. - * Java 1.4 does not have the class.getSimpleName() method (Java 1.5 and later). - * This method does the job of class.getSimpleName() in a Java 1.4 friendly manner - * @param qualifiedClassname class name as supplied by class.getName() - * @return Short name of class - */ - private String getModuleSimpleName(String qualifiedClassname){ - java.util.StringTokenizer T = new java.util.StringTokenizer(qualifiedClassname,"."); - String shortClassname = ""; - while(T.hasMoreElements()){ - shortClassname = T.nextToken(); - } - return shortClassname; - } - - /** * This method is called by a ModuleCommunicator object and supplies a callback reference. * <b>DO NOT OVERRIDE THIS METHOD</b> Module specific registration tasks should be done in doRegistration() * @param mc Callback reference to the ModuleCommunicator object This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sno...@us...> - 2013-09-14 15:49:38
|
Revision: 96 http://sourceforge.net/p/openrpg/svn/96 Author: snowdog_ Date: 2013-09-14 15:49:36 +0000 (Sat, 14 Sep 2013) Log Message: ----------- Added custom toString method to ORPGEvent object to help with event debugging Modified Paths: -------------- trunk/src/openrpg2/common/core/event/ORPGEvent.java Modified: trunk/src/openrpg2/common/core/event/ORPGEvent.java =================================================================== --- trunk/src/openrpg2/common/core/event/ORPGEvent.java 2013-09-13 06:06:50 UTC (rev 95) +++ trunk/src/openrpg2/common/core/event/ORPGEvent.java 2013-09-14 15:49:36 UTC (rev 96) @@ -57,4 +57,11 @@ public int id(){ return this.id; } public String src(){ return this.sourceModuleName; } + @Override + public String toString(){ + String m = this.sourceModuleName==null?"{NULL}":this.sourceModuleName; + String d = this.data==null?"{NULL}":this.data.toString(); + return "ORPGEvent Object(m:"+m+" e:"+this.id+" d:"+d+")"; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Mark T. <ma...@ly...> - 2013-09-14 05:52:17
|
Snowdog's been busy, it seems. Still, it's nice to see some activity here.... I've actually completely redesigned the dice roller that I wrote here since I was last working on this... learning from the mistakes I made with this one being far too generic, and as a result harder to use. The new one I came up with is actually more powerful, supporting things like adding variable numbers of dice to a die roll (ie. highest(3d6.more(5..6,1),3) would start by rolling a d6 and add 1 more die each time a 5 or 6 is rolled, and would finally take the highest 3 dice from that). Should I commit that? It's all within the openrpg2.common.dice package. Oh... one more thing... Can we use generics now? Or do we still have to use the pre-Java6 notation? Mark |
From: <sno...@us...> - 2013-09-13 06:06:55
|
Revision: 95 http://sourceforge.net/p/openrpg/svn/95 Author: snowdog_ Date: 2013-09-13 06:06:50 +0000 (Fri, 13 Sep 2013) Log Message: ----------- Continuing work on connection startup actions. Modified Paths: -------------- trunk/src/openrpg2/common/core/group/GroupServerModule.java trunk/src/openrpg2/common/core/network/NetworkClientModule.java trunk/src/openrpg2/common/core/network/NetworkServerModule.java Modified: trunk/src/openrpg2/common/core/group/GroupServerModule.java =================================================================== --- trunk/src/openrpg2/common/core/group/GroupServerModule.java 2013-09-13 03:40:28 UTC (rev 94) +++ trunk/src/openrpg2/common/core/group/GroupServerModule.java 2013-09-13 06:06:50 UTC (rev 95) @@ -34,7 +34,8 @@ import openrpg2.common.module.ServerLoadable; /** - * + * GroupServerModule is a special purpose server module that allows other modules to obtain group + * and client data. * @author snowdog */ @@ -52,6 +53,7 @@ * doRegistration is called by the ModuleManager when loading this module to * allow the module to register components and services with the ModuleManager. */ + @Override protected void doRegistration(){ modCom.registerMessageType(ORPGConstants.TYPE_GROUP, this); modCom.registerEventSender(this, GroupServerModule.EVENT_GROUPDATA_CHANGED); @@ -63,6 +65,7 @@ * processMessage() is called by message routing threads to handle messages for this module. * It is required by the NetworkedModule base class. */ + @Override public void processMessage(ORPGMessage msg){ //NOTE messages of this type ALWAYS come from the server int operation = Integer.parseInt(msg.getHeader(GroupMessageConstants.HEADER_OP)); Modified: trunk/src/openrpg2/common/core/network/NetworkClientModule.java =================================================================== --- trunk/src/openrpg2/common/core/network/NetworkClientModule.java 2013-09-13 03:40:28 UTC (rev 94) +++ trunk/src/openrpg2/common/core/network/NetworkClientModule.java 2013-09-13 06:06:50 UTC (rev 95) @@ -44,17 +44,21 @@ */ public class NetworkClientModule extends NetworkedModule implements ClientLoadable, Observer { - private final static String HEADER_OP = "OP"; - private final static int OP_NOOP = 0; - private final static int OP_JOIN = 1; - private final static int OP_DISCONNECT = 2; - private final static int OP_ALERT = 3; - private final static int OP_SHUTDOWN = 4; + public final static String HEADER_OP = "OP"; + public final static String HEADER_ID = "ID"; + public final static int OP_NOOP = 0; //no op, used as 'heartbeat' if required + public final static int OP_JOIN = 1; //used to inform server that client is ready for data + public final static int OP_DISCONNECT = 2; //used to tell server that client is disconnecting normally + public final static int OP_ALERT = 3; //used by server to force an alert message to client + public final static int OP_SHUTDOWN = 4; //used by server to inform clients of a normal server shutdown + public final static int OP_INFO = 5; //used by server to alert client of its internal 'connection id' + public final static int OP_KICK = 6; //used by server to inform client of forced disconnect by administrator public final static int EVENT_JOINED_SERVER = 1; //fired when client connects to a server public final static int EVENT_DISCONNECT = 2; //fired when client disconnects from a server private NetworkClient network = null; + private int networkId = 0; /** Creates a new instance of NetworkClientModule */ public NetworkClientModule(NetworkClient networkReference ) { @@ -75,10 +79,11 @@ //NOTE messages of this type ALWAYS come from the server int operation = Integer.parseInt(msg.getHeader(HEADER_OP)); switch(operation){ - case(OP_NOOP):{ break; } - case(OP_DISCONNECT):{ handleDisconnectMessage(msg);break; } - case(OP_ALERT):{ handleAlertMessage(msg); break; } - case(OP_SHUTDOWN):{ handleShutdownMessage(msg); break; } + case(NetworkClientModule.OP_NOOP):{ break; } + case(NetworkClientModule.OP_DISCONNECT):{ handleDisconnectMessage(msg);break; } + case(NetworkClientModule.OP_ALERT):{ handleAlertMessage(msg); break; } + case(NetworkClientModule.OP_SHUTDOWN):{ handleShutdownMessage(msg); break; } + case(NetworkClientModule.OP_INFO):{handleInfoMessage(msg); break;} default: {break;} } } @@ -110,6 +115,12 @@ private void handleShutdownMessage(ORPGMessage msg){ //TODO: handle shutdown message from server. (Disconnect from server with special notification about server shutdown) } + + private void handleInfoMessage(ORPGMessage msg){ + this.networkId = new Integer(msg.getHeader(NetworkClientModule.HEADER_ID)); + this.log.finer("Server connection Id set to "+this.networkId); + System.out.println("id = "+this.networkId); + } /** * Observer callback function for network changes. Modified: trunk/src/openrpg2/common/core/network/NetworkServerModule.java =================================================================== --- trunk/src/openrpg2/common/core/network/NetworkServerModule.java 2013-09-13 03:40:28 UTC (rev 94) +++ trunk/src/openrpg2/common/core/network/NetworkServerModule.java 2013-09-13 06:06:50 UTC (rev 95) @@ -22,9 +22,14 @@ package openrpg2.common.core.network; import java.util.Date; +import java.util.logging.Level; +import java.util.logging.Logger; import openrpg2.common.core.ORPGConstants; import openrpg2.common.core.ORPGMessage; +import openrpg2.common.core.engine.ModuleCommunicationException; import openrpg2.common.core.event.ORPGEvent; +import openrpg2.common.core.route.AddressToken; +import openrpg2.common.core.route.MessageAddress; import openrpg2.common.module.NetworkedModule; import openrpg2.common.module.ServerLoadable; @@ -38,13 +43,6 @@ */ public class NetworkServerModule extends NetworkedModule implements ServerLoadable { - private final static String HEADER_OP = "OP"; - private final static int OP_NOOP = 0; - private final static int OP_JOIN = 1; - private final static int OP_DISCONNECT = 2; - private final static int OP_ALERT = 3; - private final static int OP_SHUTDOWN = 4; - public final static int EVENT_CLIENT_JOIN = 1; public final static int EVENT_CLIENT_DISCONNECT = 2; @@ -65,18 +63,31 @@ @Override public void processMessage(ORPGMessage msg){ int clientId = msg.getOriginatorId(); - int operation = Integer.parseInt(msg.getHeader(NetworkServerModule.HEADER_OP)); + int operation = Integer.parseInt(msg.getHeader(NetworkClientModule.HEADER_OP)); switch(operation){ - case(NetworkServerModule.OP_NOOP):{ break; } - case(NetworkServerModule.OP_JOIN):{ handleJoinMessage(msg);break; } - case(NetworkServerModule.OP_DISCONNECT):{ handleDisconnectMessage(msg);break; } - case(NetworkServerModule.OP_ALERT):{ handleAlertMessage(msg); break; } - case(NetworkServerModule.OP_SHUTDOWN):{ handleShutdownMessage(msg); break; } + case(NetworkClientModule.OP_NOOP):{ break; } + case(NetworkClientModule.OP_JOIN):{ handleJoinMessage(msg);break; } + case(NetworkClientModule.OP_DISCONNECT):{ handleDisconnectMessage(msg);break; } + case(NetworkClientModule.OP_ALERT):{ handleAlertMessage(msg); break; } + case(NetworkClientModule.OP_SHUTDOWN):{ handleShutdownMessage(msg); break; } default: {break;} } } - private void handleJoinMessage(ORPGMessage msg){ + private void handleJoinMessage(ORPGMessage msg) { + //send a message back to client to let them know what their connection ID is + ORPGMessage m = new ORPGMessage(); + m.setMessageType(ORPGConstants.TYPE_NETWORK); + m.setHeader(NetworkClientModule.HEADER_OP, NetworkClientModule.OP_INFO); + m.setHeader(NetworkClientModule.HEADER_ID, msg.getOriginatorId()); + m.setDestination( new MessageAddress(new AddressToken(msg.getOriginatorId()))); + try { + this.modCom.sendToNetwork(m); + System.out.println("handleJoinMessage() sending "+msg.getAsString()); + } catch (ModuleCommunicationException ex) { + Logger.getLogger(NetworkServerModule.class.getName()).log(Level.SEVERE, "Failed to send ID message "+msg.toString(), ex); + } + //Fire an event to all watching modules that the client has joined the server ORPGEvent e = new ORPGEvent(this,NetworkServerModule.EVENT_CLIENT_JOIN); e.data = new Integer(msg.getOriginatorId()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sno...@us...> - 2013-09-13 03:40:31
|
Revision: 94 http://sourceforge.net/p/openrpg/svn/94 Author: snowdog_ Date: 2013-09-13 03:40:28 +0000 (Fri, 13 Sep 2013) Log Message: ----------- Minor code cleanups Modified Paths: -------------- trunk/src/openrpg2/common/core/group/GroupClientModule.java trunk/src/openrpg2/common/core/route/RouteServiceThread.java Property Changed: ---------------- trunk/src/ Index: trunk/src =================================================================== --- trunk/src 2013-09-12 21:20:30 UTC (rev 93) +++ trunk/src 2013-09-13 03:40:28 UTC (rev 94) Property changes on: trunk/src ___________________________________________________________________ Added: svn:ignore ## -0,0 +1 ## +._.DS_Store Modified: trunk/src/openrpg2/common/core/group/GroupClientModule.java =================================================================== --- trunk/src/openrpg2/common/core/group/GroupClientModule.java 2013-09-12 21:20:30 UTC (rev 93) +++ trunk/src/openrpg2/common/core/group/GroupClientModule.java 2013-09-13 03:40:28 UTC (rev 94) @@ -23,8 +23,6 @@ import openrpg2.common.core.ORPGConstants; import openrpg2.common.core.ORPGMessage; -import openrpg2.common.core.route.AddressToken; -import openrpg2.common.core.route.MessageAddress; import openrpg2.common.module.ClientLoadable; import openrpg2.common.module.NetworkedModule; @@ -32,7 +30,7 @@ /** * GroupClientModule is the loadable module that tracks client grouping * information client side. This module makes requests for group changes - * for the client to the GroupServerModule on the server and recieves + * for the client to the GroupServerModule on the server and receives * confirmation and notification of all group changing activities from * the server. * @@ -53,6 +51,7 @@ * doRegistration is called by the ModuleManager when loading this module to * allow the module to register components and services with the ModuleManager. */ + @Override protected void doRegistration(){ modCom.registerMessageType(ORPGConstants.TYPE_GROUP, this); } @@ -61,6 +60,7 @@ * processMessage() is called by message routing threads to handle messages for this module. * It is required by the NetworkedModule base class. */ + @Override public void processMessage(ORPGMessage msg){ //NOTE messages of this type ALWAYS come from the server int operation = Integer.parseInt(msg.getHeader(GroupMessageConstants.HEADER_OP)); Modified: trunk/src/openrpg2/common/core/route/RouteServiceThread.java =================================================================== --- trunk/src/openrpg2/common/core/route/RouteServiceThread.java 2013-09-12 21:20:30 UTC (rev 93) +++ trunk/src/openrpg2/common/core/route/RouteServiceThread.java 2013-09-13 03:40:28 UTC (rev 94) @@ -141,7 +141,6 @@ //TODO: Add inbound filter hook //TODO: Add code to locate module from module manager and process message using module handler method - System.out.println("---> "+msg.getAsString()); NetworkedModule handler = null; try{ if( msg.verifyHeader()){ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sno...@us...> - 2013-09-12 21:20:34
|
Revision: 93 http://sourceforge.net/p/openrpg/svn/93 Author: snowdog_ Date: 2013-09-12 21:20:30 +0000 (Thu, 12 Sep 2013) Log Message: ----------- Added extra explanation comments to the ExampleClientModule code and cleaned it up a bit. Converted the ExampleClientModule to access the data portion of the ORPGMessage structure also. Modified Paths: -------------- trunk/src/openrpg2/client/core/modules/ExampleClientModule.java trunk/src/openrpg2/common/core/network/NetworkClientModule.java Modified: trunk/src/openrpg2/client/core/modules/ExampleClientModule.java =================================================================== --- trunk/src/openrpg2/client/core/modules/ExampleClientModule.java 2013-09-12 21:02:35 UTC (rev 92) +++ trunk/src/openrpg2/client/core/modules/ExampleClientModule.java 2013-09-12 21:20:30 UTC (rev 93) @@ -37,11 +37,35 @@ import openrpg2.common.module.NetworkedModule; /** - * + * This is a simple example of a Networked module with a graphical interface. * @author Snowdog */ public class ExampleClientModule extends NetworkedModule implements ClientLoadable, ActionListener{ + /* + * MESSAGE_TYPE + * Always a good idea to include the ORPGMessage type identifier for + * a module as a public constant. This allows other modules easy access. + * Convention is to use the module class name but this is not strictly + * enforced. Modules sending larger volumes of messages should have a + * short identifier to reduce bandwidth consumption. + */ + public static final String MESSAGE_TYPE = "POPUP"; // convention would be "ExampleClientModule" instead + + + /** + * HEADER KEYS + * Its good practice to include any header key identifiers as + * public final static strings. This allows other modules to access them in + * order to send this module information via messages. + * Always a good idea to avoid hard coding things like this directly + * into the code ;) + */ + public static final String OPERATION = "OP"; + public static final String HEADER_KEY2 = "HK2"; + + public static final int OP_POPUP = 1; + JPanel panel = null; JButton sendButton = null; JLabel windowText = null; @@ -63,21 +87,58 @@ panel.add(sendButton); } + @Override public void actionPerformed( ActionEvent event ){ if (event.getSource() == this.sendButton){ sendPopupMessage(); } } + /** + * This method formats a new outbound ORPGMessage and sends it to the server + */ private void sendPopupMessage(){ - log.finer("sendPopupMessage() called"); - ORPGMessage msg = new ORPGMessage(); - msg.setHandlerId("Popup"); - msg.setHeader("PopText","ExampleClientModule is annoying you with a popup"); + log.finer("sendPopupMessage() called"); //log that the method was called to the DevConsole (fine level) + ORPGMessage msg = new ORPGMessage(); //create a new empty ORPGMessage + msg.setMessageType(ExampleClientModule.MESSAGE_TYPE); //tag the message with the id for this module + + /* + * Simple messages may only require small amounts of data to be sent. In these cases it is + * efficent to simply embed them into the header of the ORPGMessage. This is perfect for + * a small notification, perhaps a status change, or simple result of an operation. If your + * data is of any kind of significant size (say an XML fragment) then it should be placed + * into the message as data instead. The server (and client) will parse the header during + * message transport but the message data is passed through as a simple binary blob! + */ + int sampleInteger = 0; + msg.setHeader(ExampleClientModule.OPERATION, 1); //example of sending small data in the message header + msg.setHeader(ExampleClientModule.HEADER_KEY2, "sampleString");//example of sending small data in the message header + + /* + * MESSAGE DATA USAGE + * As mentioned above the DATA portion of the ORPGMessage passes through + * to the receiving module unparsed and unchanged. This allows for + * effecient transport of large datasets without causing delays (due to + * header parsing). If you need to move anything more than a couple simple + * data types shift your into the message data component. + */ + msg.setDataAsString("ExampleClientModule is annoying you with a popup"); + /* + * MessageAddress + * This is where you set where the message is headed to. + * Each messageAddress holds one or more AddressTokens + * Each AddressToken defines a specific client or set of clients to + * deliver the message to. + * In this case we are creating a message to send to all users in the + * 'Lobby' (default group) of the server and then adding the MessageAddress to + * the ORPGMessage itself (setDestination) + */ MessageAddress sendTo = new MessageAddress(); sendTo.append(new AddressToken(AddressToken.ALL,GroupManager.LOBBY_ID)); //send to all clients msg.setDestination(sendTo); + + /* now try sending the message to the network...*/ try{ this.modCom.sendToNetwork(msg); }catch(ModuleCommunicationException e){ @@ -87,17 +148,39 @@ } } + + /** + * This is where all incoming messages will arrive. + * First we check what type of message it is (is it ours), this is not strictly + * required but is a good sanity check + * In this case as ALL messages from this module are for the popup window + * we are ignoring all header info and converting the data back into a string + * for display. + * If we wanted to handle different types of messages we can assign a header + * variable (example above ExampleClientModule.OPERATION) when sending + * the message and inspect its value to figure out what kind of message + * the module is receiving (in example above the value would be "1"). + * Note: all header values are strings in inbound messages!!! + */ + @Override public void processMessage(ORPGMessage msg){ - if ( msg.getHandlerId().compareTo("Popup") == 0 ){ - String popupMessage = msg.getHeader("PopText"); + if ( msg.getMessageType().compareTo(ExampleClientModule.MESSAGE_TYPE) == 0 ){ + String popupMessage = msg.getDataAsString(); JOptionPane.showMessageDialog(panel,popupMessage,"ExacmpleClientModule Popup",JOptionPane.INFORMATION_MESSAGE); } } + /** + * The doRegistration method holds all the module binding calls. + * These calls will register with the various subsystems to notify various + * parts of the ORPG2 core as to what this module is interested in and/or + * provides to other modules. + */ + @Override public void doRegistration(){ log.finer("doRegistration() called"); - this.modCom.registerMessageType("Popup", this); - this.modCom.registerGUIComponent("Popup", panel); + this.modCom.registerMessageType(ExampleClientModule.MESSAGE_TYPE, this); + this.modCom.registerGUIComponent(ExampleClientModule.MESSAGE_TYPE, panel); } } Modified: trunk/src/openrpg2/common/core/network/NetworkClientModule.java =================================================================== --- trunk/src/openrpg2/common/core/network/NetworkClientModule.java 2013-09-12 21:02:35 UTC (rev 92) +++ trunk/src/openrpg2/common/core/network/NetworkClientModule.java 2013-09-12 21:20:30 UTC (rev 93) @@ -88,6 +88,7 @@ MessageAddress m = new MessageAddress(); m.append(new AddressToken());//default AddressToken directs to connected server! msg.setDestination(m); + msg.setMessageType(ORPGConstants.TYPE_NETWORK); msg.setHeader(HEADER_OP, OP_JOIN); try { this.modCom.sendToNetwork(msg); //try to send message to server (throws exception on error) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sno...@us...> - 2013-09-12 21:02:38
|
Revision: 92 http://sourceforge.net/p/openrpg/svn/92 Author: snowdog_ Date: 2013-09-12 21:02:35 +0000 (Thu, 12 Sep 2013) Log Message: ----------- Depreciated getHandlerId() in favor of getMessageType() in order to make intent a little clearer for future module developers. Modified Paths: -------------- trunk/src/openrpg2/common/core/ORPGMessage.java Modified: trunk/src/openrpg2/common/core/ORPGMessage.java =================================================================== --- trunk/src/openrpg2/common/core/ORPGMessage.java 2013-09-12 20:53:03 UTC (rev 91) +++ trunk/src/openrpg2/common/core/ORPGMessage.java 2013-09-12 21:02:35 UTC (rev 92) @@ -24,8 +24,6 @@ package openrpg2.common.core; import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.CharBuffer; import java.nio.charset.Charset; import java.util.Enumeration; import java.util.Hashtable; @@ -146,6 +144,7 @@ * Retrieves the identifier for the target module of this message. * If the handler is null a 'TYPE_UNKNOWN' will be returned instead. * <i>Note: having TYPE_UNKNOWN is actually an error and this message will fail verifyHeader()</i> + * @deprecated Use getMessageType() instead * @return Identifier as String */ public String getHandlerId(){ @@ -154,6 +153,16 @@ } /** + * gets the identifier of the target module of this message. + * This method is clearer for developers to use than the old getHandlerId() + * @return String identifier for handing module + */ + public String getMessageType(){ + if( handlerId == null){ return ORPGConstants.TYPE_UNKNOWN; } + return handlerId; + } + + /** * Sets the identifier of the target module of this message. * @deprecated Use setMessageType() instead. * @param handler This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sno...@us...> - 2013-09-12 20:53:06
|
Revision: 91 http://sourceforge.net/p/openrpg/svn/91 Author: snowdog_ Date: 2013-09-12 20:53:03 +0000 (Thu, 12 Sep 2013) Log Message: ----------- Depreciated setHandlerId() in favor of setMessageType() in order to make intent a little clearer for future module developers. Added String specific data encoding functions to ORPGMessage object to handle 'common' task of sending strings safely/easily. Modified Paths: -------------- trunk/src/openrpg2/common/core/ORPGMessage.java Modified: trunk/src/openrpg2/common/core/ORPGMessage.java =================================================================== --- trunk/src/openrpg2/common/core/ORPGMessage.java 2013-09-12 18:16:11 UTC (rev 90) +++ trunk/src/openrpg2/common/core/ORPGMessage.java 2013-09-12 20:53:03 UTC (rev 91) @@ -23,6 +23,10 @@ package openrpg2.common.core; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.CharBuffer; +import java.nio.charset.Charset; import java.util.Enumeration; import java.util.Hashtable; import java.util.Iterator; @@ -96,7 +100,7 @@ */ public void setData(byte[] rawData){ data = rawData; - } + } /** * Gets the binary payload (data) for this message. @@ -108,6 +112,30 @@ return d; } + /** + * Places a string into the data portion of the message + * in a binary safe way. This guarantees the byte order will be predictable + * regardless of the consumers default character encoding + * @param data as String + */ + public void setDataAsString(String data){ + this.data = Charset.forName("UTF-16BE").encode(data).array(); + } + + /** + * Decodes the data as encoded by setDataAsString() in a binary safe manner. + * This ensures that strings are reconstructed properly from data regardless + * of default system encoding or 'endianness' of the host system. + * @see setDataAsString + * @return String of data + */ + public String getDataAsString(){ + if( this.data == null ){ return "";} + Charset c = Charset.forName("UTF-16BE"); + return c.decode(ByteBuffer.wrap(this.data)).toString(); + } + + public NetworkMessage asNetworkMessage(){ setHeader(ORPGConstants.MESSAGE_DESTINATION, destination.encode()); NetworkMessage netmsg = new NetworkMessage(this.getEncodedHeaderString(), this.getData()); @@ -127,6 +155,7 @@ /** * Sets the identifier of the target module of this message. + * @deprecated Use setMessageType() instead. * @param handler */ public void setHandlerId( String handler ){ @@ -135,6 +164,18 @@ } /** + * Sets the identifier of the target module of this message. + * This method is clear for developers to use than the old setHandlerId() + * @param moduleIdentifier + */ + public void setMessageType(String moduleIdentifier){ + setHeader(ORPGConstants.MESSAGE_TYPE, moduleIdentifier); + handlerId = moduleIdentifier; + } + + + + /** * Get the address this message is being sent too * @return destination address */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sno...@us...> - 2013-09-12 18:16:14
|
Revision: 90 http://sourceforge.net/p/openrpg/svn/90 Author: snowdog_ Date: 2013-09-12 18:16:11 +0000 (Thu, 12 Sep 2013) Log Message: ----------- Resolved some routing issues where malformed messages were causing exceptions and hanging route treads. Added verification check code to ORPGMessage class. Modified Paths: -------------- trunk/src/openrpg2/common/core/ORPGConstants.java trunk/src/openrpg2/common/core/ORPGMessage.java trunk/src/openrpg2/common/core/logging/DevConsole.java trunk/src/openrpg2/common/core/logging/SingleLineFormatter.java trunk/src/openrpg2/common/core/route/RouteServiceThread.java Added Paths: ----------- trunk/src/openrpg2/common/core/route/InvalidMessageHandlerException.java Modified: trunk/src/openrpg2/common/core/ORPGConstants.java =================================================================== --- trunk/src/openrpg2/common/core/ORPGConstants.java 2013-09-12 17:16:02 UTC (rev 89) +++ trunk/src/openrpg2/common/core/ORPGConstants.java 2013-09-12 18:16:11 UTC (rev 90) @@ -49,6 +49,7 @@ //These are special message type identifiers that are part of the core implementation and are therefore reserved static final public String TYPE_NETWORK = "_NET_"; static final public String TYPE_GROUP = "_GRP_"; + static final public String TYPE_UNKNOWN = "_NULL_"; //OPERATION MODE CONSTANTS Modified: trunk/src/openrpg2/common/core/ORPGMessage.java =================================================================== --- trunk/src/openrpg2/common/core/ORPGMessage.java 2013-09-12 17:16:02 UTC (rev 89) +++ trunk/src/openrpg2/common/core/ORPGMessage.java 2013-09-12 18:16:11 UTC (rev 90) @@ -29,6 +29,8 @@ import java.util.Map; import openrpg2.common.core.network.HeaderEncoder; import openrpg2.common.core.network.NetworkMessage; +import openrpg2.common.core.route.InvalidMessageHandlerException; +import openrpg2.common.core.route.InvalidMessageTargetException; import openrpg2.common.core.route.MessageAddress; @@ -114,9 +116,12 @@ /** * Retrieves the identifier for the target module of this message. + * If the handler is null a 'TYPE_UNKNOWN' will be returned instead. + * <i>Note: having TYPE_UNKNOWN is actually an error and this message will fail verifyHeader()</i> * @return Identifier as String */ public String getHandlerId(){ + if( handlerId == null){ return ORPGConstants.TYPE_UNKNOWN; } return handlerId; } @@ -247,6 +252,21 @@ } /** + * VerifyHeader allows for a sanity check to be performed before messages + * are accepted at the network layer. This helps prevent exceptions from + * being thrown in unexpected places and help ensure the integrity of + * message processing threads, especially in the server. + * @return true if verified false if not + */ + public boolean verifyHeader() + throws InvalidMessageHandlerException, + InvalidMessageTargetException { + boolean verified = true; + if( destination == null ){ throw new InvalidMessageTargetException("No Target Desination Specified"); } + if( handlerId == null){ throw new InvalidMessageHandlerException("No Handler Specified"); } + return verified; + } + /** * Debugging only. Returns the header information (key value pairs) as a string and includes a * byte count of data (if present). * @return string representation of ORPGMessage @@ -265,7 +285,7 @@ } s.append("[DATA: "); if( this.data == null ){ s.append("NULL]"); } - else{ s.append(this.data.length); s.append(" BYTES"); } + else{ s.append(this.data.length); s.append(" BYTES]"); } return s.toString(); } } Modified: trunk/src/openrpg2/common/core/logging/DevConsole.java =================================================================== --- trunk/src/openrpg2/common/core/logging/DevConsole.java 2013-09-12 17:16:02 UTC (rev 89) +++ trunk/src/openrpg2/common/core/logging/DevConsole.java 2013-09-12 18:16:11 UTC (rev 90) @@ -28,9 +28,9 @@ /** - * Developers Console is a convienent place to send warnings, alerts, and debugging text for developers. - * Also acts as a common gateway to the OpenRPG loggin mechanisms.<br> - * Behavior of the developers console not only gives immediate feedback to opensource developers but also + * Developers Console is a convenient place to send warnings, alerts, and debugging text for developers. + * Also acts as a common gateway to the OpenRPG logging mechanisms.<br> + * Behavior of the developers console not only gives immediate feedback to open source developers but also * functions as an session auto-logger to allow developers to review output of application runs during testing. * @author Snowdog */ Modified: trunk/src/openrpg2/common/core/logging/SingleLineFormatter.java =================================================================== --- trunk/src/openrpg2/common/core/logging/SingleLineFormatter.java 2013-09-12 17:16:02 UTC (rev 89) +++ trunk/src/openrpg2/common/core/logging/SingleLineFormatter.java 2013-09-12 18:16:11 UTC (rev 90) @@ -35,12 +35,13 @@ public SingleLineFormatter() { } + @Override public String format(LogRecord record){ Date d = new Date(record.getMillis()); StringBuffer a = new StringBuffer(); a.append(DateFormat.getDateInstance(DateFormat.SHORT).format(d)); a.append(" "); - a.append(DateFormat.getTimeInstance().getTimeInstance(DateFormat.SHORT).format(d)); + a.append(DateFormat.getTimeInstance(DateFormat.SHORT).format(d)); a.append(" ["); a.append(record.getLevel().getLocalizedName()); a.append("] ("); Added: trunk/src/openrpg2/common/core/route/InvalidMessageHandlerException.java =================================================================== --- trunk/src/openrpg2/common/core/route/InvalidMessageHandlerException.java (rev 0) +++ trunk/src/openrpg2/common/core/route/InvalidMessageHandlerException.java 2013-09-12 18:16:11 UTC (rev 90) @@ -0,0 +1,58 @@ +/* + * InvalidMessageHandlerException.java + * + * Author: Snowdog + * Created: September 12, 2013, 10:25 AM + * + * ==================================================================== + * Copyright (C) 2005-2006 The OpenRPG Project (www.openrpg.com) + * + * This program 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. + * + * This software 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 on www.gnu.org for more details. + * ==================================================================== + */ + +package openrpg2.common.core.route; + +/** + * InvalidMessageHandlerException should be thrown when an ORPG message + * has an invalid (or null if missing entirely) handler field in its header + * @author snowdog + */ +public class InvalidMessageHandlerException extends java.lang.Exception { + /** + * Creates a new InvalidMessageHandlerException with a null detail message. + */ + public InvalidMessageHandlerException() { + super(); + } + /** + * Creates a new InvalidMessageHandlerException with a detail message. + * @param msg Detail message about why this exception was thrown + */ + public InvalidMessageHandlerException(String msg){ + super(msg); + } + /** + * Creates a new InvalidMessageHandlerException with a detail message and a cause + * @param msg Detail message about why this exception was thrown + * @param t Throwable cause + */ + public InvalidMessageHandlerException(String msg, Throwable t){ + super(msg,t); + } + /** + * Creates a new InvalidMessageHandlerException with a null detail message and a cause + * @param t Throwable cause + */ + public InvalidMessageHandlerException(Throwable t){ + super(t); + } +} Modified: trunk/src/openrpg2/common/core/route/RouteServiceThread.java =================================================================== --- trunk/src/openrpg2/common/core/route/RouteServiceThread.java 2013-09-12 17:16:02 UTC (rev 89) +++ trunk/src/openrpg2/common/core/route/RouteServiceThread.java 2013-09-12 18:16:11 UTC (rev 90) @@ -141,11 +141,14 @@ //TODO: Add inbound filter hook //TODO: Add code to locate module from module manager and process message using module handler method + System.out.println("---> "+msg.getAsString()); NetworkedModule handler = null; try{ - handler = moduleLocator.getNetworkedModuleReference(msg.getHandlerId()); - }catch( NoSuchModuleException nsme){ - //handler module doesn't exist. Try to obtain a default handler. + if( msg.verifyHeader()){ + handler = moduleLocator.getNetworkedModuleReference(msg.getHandlerId()); + } + }catch( InvalidMessageHandlerException | NoSuchModuleException nsme){ + //handler module doesn't exist. or not defined in message. Try to obtain a default handler. try{ handler = moduleLocator.getDefaultModuleReference(); }catch( NoSuchModuleException ndmh){ @@ -153,8 +156,14 @@ log.fine("acceptService() abandoning message. No Handler."); msg = null; } + }catch(InvalidMessageTargetException imte){ + log.fine("acceptService() abandoning message. Invalid Destination."); + msg = null; }finally{ - processMessage(handler); + if((msg != null)&&( handler == null)){ + //verification failed but no exceptions thrown... we are bailing out on this message + log.fine("acceptServer() abandoning message. Verification failed."); + }else{processMessage(handler); } } msg = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sno...@us...> - 2013-09-12 17:16:05
|
Revision: 89 http://sourceforge.net/p/openrpg/svn/89 Author: snowdog_ Date: 2013-09-12 17:16:02 +0000 (Thu, 12 Sep 2013) Log Message: ----------- Added getAsString method to ORPGMessage to convert message to string to simplify debugging of message headers Modified Paths: -------------- trunk/src/openrpg2/common/core/ORPGMessage.java Modified: trunk/src/openrpg2/common/core/ORPGMessage.java =================================================================== --- trunk/src/openrpg2/common/core/ORPGMessage.java 2013-09-12 05:55:34 UTC (rev 88) +++ trunk/src/openrpg2/common/core/ORPGMessage.java 2013-09-12 17:16:02 UTC (rev 89) @@ -25,6 +25,8 @@ import java.util.Enumeration; import java.util.Hashtable; +import java.util.Iterator; +import java.util.Map; import openrpg2.common.core.network.HeaderEncoder; import openrpg2.common.core.network.NetworkMessage; import openrpg2.common.core.route.MessageAddress; @@ -115,7 +117,7 @@ * @return Identifier as String */ public String getHandlerId(){ - return new String(handlerId); + return handlerId; } /** @@ -169,7 +171,7 @@ * @return value associated with key as string */ public String getHeader(String key){ - String s = ""; + String s; if (! header.containsKey(key)){ return null; } @@ -243,4 +245,27 @@ public int[] getFinalRecipientList(){ return recipients; } + + /** + * Debugging only. Returns the header information (key value pairs) as a string and includes a + * byte count of data (if present). + * @return string representation of ORPGMessage + */ + public String getAsString(){ + StringBuilder s = new StringBuilder(); + Iterator it = this.header.entrySet().iterator(); + s.append("ORPGMessage: "); + while (it.hasNext()) { + Map.Entry pairs = (Map.Entry)it.next(); + s.append("("); + s.append(pairs.getKey()); + s.append(","); + s.append(pairs.getValue()); + s.append(") "); + } + s.append("[DATA: "); + if( this.data == null ){ s.append("NULL]"); } + else{ s.append(this.data.length); s.append(" BYTES"); } + return s.toString(); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sno...@us...> - 2013-09-12 05:55:38
|
Revision: 88 http://sourceforge.net/p/openrpg/svn/88 Author: snowdog_ Date: 2013-09-12 05:55:34 +0000 (Thu, 12 Sep 2013) Log Message: ----------- Integrated network event handling for NetworkClientModule. Several bug fixes on ModuleEventManger that were causing null pointer exceptions. Modified Paths: -------------- trunk/src/openrpg2/common/core/engine/ModuleManager.java trunk/src/openrpg2/common/core/event/ModuleEventManager.java trunk/src/openrpg2/common/core/network/NetworkClient.java trunk/src/openrpg2/common/core/network/NetworkClientModule.java trunk/src/openrpg2/common/core/route/AddressToken.java Modified: trunk/src/openrpg2/common/core/engine/ModuleManager.java =================================================================== --- trunk/src/openrpg2/common/core/engine/ModuleManager.java 2013-09-10 23:56:07 UTC (rev 87) +++ trunk/src/openrpg2/common/core/engine/ModuleManager.java 2013-09-12 05:55:34 UTC (rev 88) @@ -190,8 +190,8 @@ */ private void init() throws NoSuchModuleException { moduleLoader.setModuleManagerCallback(this); + moduleLoader.loadNetworkModule(); moduleLoader.loadGroupModule(groupManager); - moduleLoader.loadNetworkModule(); moduleLoader.loadModules(this); } Modified: trunk/src/openrpg2/common/core/event/ModuleEventManager.java =================================================================== --- trunk/src/openrpg2/common/core/event/ModuleEventManager.java 2013-09-10 23:56:07 UTC (rev 87) +++ trunk/src/openrpg2/common/core/event/ModuleEventManager.java 2013-09-12 05:55:34 UTC (rev 88) @@ -23,6 +23,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; +import java.util.Map; +import java.util.Set; import openrpg2.common.module.ModuleEventListener; /** @@ -78,9 +80,11 @@ * @param eventId Id of the event to listen for */ public void registerEventListener(ModuleEventListener listener, String moduleName, int eventId){ + //System.out.println("registerEventListener("+listener.toString()+","+moduleName+","+eventId); registerEventSender(moduleName,eventId); HashMap<Integer,ArrayList> events; ArrayList<ModuleEventListener> watchers; + events = this.eventMap.get(moduleName); if( events.containsKey(eventId)){ watchers = events.get(eventId); @@ -93,6 +97,7 @@ watchers.add(listener); events.put(eventId, watchers); } + } /** @@ -103,7 +108,8 @@ */ public void sendEvent(ORPGEvent e){ ArrayList<ModuleEventListener> watchers = getListeners(e.sourceModuleName,e.id); - Iterator<ModuleEventListener> it = watchers.iterator(); + if( watchers == null){ return; }//nothing to do + Iterator<ModuleEventListener> it = watchers.iterator(); while(it.hasNext()) { ModuleEventListener target = it.next(); @@ -113,13 +119,37 @@ } private ArrayList<ModuleEventListener> getListeners(String m, int i){ - HashMap<Integer,ArrayList> events; + HashMap<Integer,ArrayList> events = null; ArrayList<ModuleEventListener> watchers = new ArrayList<>(); - events = this.eventMap.get(m); - if( events.containsKey(i)){ - watchers = events.get(i); + if(this.eventMap.containsKey(m)){ + events = this.eventMap.get(m); + if( events.containsKey(i)){ + watchers = events.get(i); + } } return watchers; } + private void DEBUG_PRINT_LISTENER_MAP(){ + if(this.eventMap.isEmpty()){ System.out.println("LISTENER MAP EMPTY"); return;} + System.out.println("Listener Map contains "+eventMap.size()+" entries"); + + + Set<Map.Entry<String, HashMap>> entrySet1 = this.eventMap.entrySet(); + Iterator<Map.Entry<String, HashMap>> entrySetIterator = entrySet1.iterator(); + while (entrySetIterator.hasNext()) { + Map.Entry entry = entrySetIterator.next(); + System.out.println("Module Name: " + entry.getKey()); + HashMap<Integer,ArrayList> events = (HashMap<Integer,ArrayList>) entry.getValue(); + Set<Map.Entry<Integer,ArrayList>> entrySet2 = events.entrySet(); + Iterator<Map.Entry<Integer,ArrayList>> iterator2 = entrySet2.iterator(); + while(iterator2.hasNext()){ + Map.Entry entry2 = iterator2.next(); + System.out.print(" {"+entry2.getKey()+"} "); + ArrayList<ModuleEventListener> modules = (ArrayList<ModuleEventListener>) entry2.getValue(); + if( modules == null) {System.out.println("NULL");} + else{ System.out.print("Modules: "+modules.size()); } + } + } + } } Modified: trunk/src/openrpg2/common/core/network/NetworkClient.java =================================================================== --- trunk/src/openrpg2/common/core/network/NetworkClient.java 2013-09-10 23:56:07 UTC (rev 87) +++ trunk/src/openrpg2/common/core/network/NetworkClient.java 2013-09-12 05:55:34 UTC (rev 88) @@ -42,7 +42,7 @@ * @author snowdog */ -public class NetworkClient implements NetworkMessageRelay, NetworkModuleProvider{ +public class NetworkClient implements NetworkMessageRelay, NetworkConnectionNotifier, NetworkModuleProvider{ private ORPGMessageQueue inQueue; private ORPGMessageQueue outQueue; @@ -52,6 +52,7 @@ private Selector selector = null; private Thread readThread = null; private Thread writeThread = null; + private NetworkConnectionAlerter connectionAlerter = new NetworkConnectionAlerter(); /** * Network API for a client side network connection. @@ -82,12 +83,16 @@ writeThread = null; if(connection.connect(serverAddress)){ networkThreads(); + + //connection established, notify NetworkClientModule! + this.connectionAlerter.announceConnection(0); //clientId for announcement is pointless on client side + return true; - }else{ - return false; } + return false; } + /** * check if this NetworkClient is connected to a server * @return true if connected to a server @@ -135,6 +140,8 @@ outQueue.pullMessage(); } + this.connectionAlerter.announceDisconnection(0); //clientId for announcement is pointless on client side + //remove the network connection object connection = null; @@ -203,6 +210,7 @@ } readThread = new Thread(){ + @Override public void run(){ int readyKeys = 0; while(runFlag){ @@ -255,6 +263,7 @@ private void writeThread(){ writeThread = new Thread(){ + @Override public void run(){ while(runFlag){ try{ @@ -285,6 +294,7 @@ writeThread.start(); } //methods to satisfy NetworkMessageRelay interface + @Override public Observable addMessageQueueObserver(Observer o){ inQueue.addObserver(o); return inQueue; //return reference to object for comparison only in case more than one observable is being monitored. @@ -295,6 +305,7 @@ * @return boolean. True on success, False on failure */ + @Override public boolean putORPGMessage(ORPGMessage msg){ return sendMessage(msg); } @@ -303,6 +314,7 @@ * @throws openrpg2.common.core.network.NoMessageAvailableException Thrown if no messages are available for retrieval * @return ORPGMessage object */ + @Override public ORPGMessage getORPGMessage() throws NoMessageAvailableException{ ORPGMessage msg = readMessage(); if (msg == null){ @@ -315,6 +327,7 @@ * Check if ORPGMessage can be retrieved with getORPGMessage() method * @return True if 1 or more ORPGMessages are ready for retrieval otherwise false. */ + @Override public boolean hasORPGMessage(){ return messageAvailable(); } @@ -323,4 +336,15 @@ public NetworkedModule getNetworkModule(){ return new NetworkClientModule(this); } + + /** + * Required for implementation of NetworkConnectionNotifier interface. + * Allows other core components to be notified when client connects or disconnects from a server. + * @param o An Observer Object to register for network state notification + */ + @Override + + public void registerNetworkConnectionObserver(Observer o){ + connectionAlerter.addObserver(o); + } } Modified: trunk/src/openrpg2/common/core/network/NetworkClientModule.java =================================================================== --- trunk/src/openrpg2/common/core/network/NetworkClientModule.java 2013-09-10 23:56:07 UTC (rev 87) +++ trunk/src/openrpg2/common/core/network/NetworkClientModule.java 2013-09-12 05:55:34 UTC (rev 88) @@ -21,39 +21,56 @@ package openrpg2.common.core.network; +import java.util.Observable; +import java.util.Observer; +import java.util.logging.Level; +import java.util.logging.Logger; import openrpg2.common.core.ORPGConstants; import openrpg2.common.core.ORPGMessage; +import openrpg2.common.core.engine.ModuleCommunicationException; +import openrpg2.common.core.event.ORPGEvent; +import openrpg2.common.core.route.AddressToken; +import openrpg2.common.core.route.MessageAddress; import openrpg2.common.module.ClientLoadable; import openrpg2.common.module.NetworkedModule; /** * The NetworkClientModule is a special client loadable module to provide network information to other modules - * in a controled and safe manner. This class is loaded into the module manager and provides an API through which + * in a controlled and safe manner. This class is loaded into the module manager and provides an API through which * network related information can be obtained by other modules and thus keep other modules from relying directly * on the network's specific implementation. This module also provides support for message based requests for * graceful disconnection of/by a client or server. * @author Snowdog */ -public class NetworkClientModule extends NetworkedModule implements ClientLoadable { +public class NetworkClientModule extends NetworkedModule implements ClientLoadable, Observer { private final static String HEADER_OP = "OP"; private final static int OP_NOOP = 0; - private final static int OP_DISCONNECT = 1; - private final static int OP_ALERT = 2; - private final static int OP_SHUTDOWN = 3; + private final static int OP_JOIN = 1; + private final static int OP_DISCONNECT = 2; + private final static int OP_ALERT = 3; + private final static int OP_SHUTDOWN = 4; + public final static int EVENT_JOINED_SERVER = 1; //fired when client connects to a server + public final static int EVENT_DISCONNECT = 2; //fired when client disconnects from a server + private NetworkClient network = null; /** Creates a new instance of NetworkClientModule */ public NetworkClientModule(NetworkClient networkReference ) { network = networkReference; - } + @Override public void doRegistration(){ + network.registerNetworkConnectionObserver(this); modCom.registerMessageType(ORPGConstants.TYPE_NETWORK, this); + this.modCom.registerEventSender(this, NetworkClientModule.EVENT_JOINED_SERVER); + this.modCom.registerEventSender(this, NetworkClientModule.EVENT_DISCONNECT); + } + @Override public void processMessage(ORPGMessage msg){ //NOTE messages of this type ALWAYS come from the server int operation = Integer.parseInt(msg.getHeader(HEADER_OP)); @@ -66,6 +83,20 @@ } } + public void sendJoinMessage(){ + ORPGMessage msg = new ORPGMessage(); + MessageAddress m = new MessageAddress(); + m.append(new AddressToken());//default AddressToken directs to connected server! + msg.setDestination(m); + msg.setHeader(HEADER_OP, OP_JOIN); + try { + this.modCom.sendToNetwork(msg); //try to send message to server (throws exception on error) + ORPGEvent e = new ORPGEvent(this, NetworkClientModule.EVENT_JOINED_SERVER); + this.modCom.generateEvent(e); //notify other modules of JOIN event. + } catch (ModuleCommunicationException ex) { + Logger.getLogger(NetworkClientModule.class.getName()).log(Level.SEVERE, "Failed to send JOIN message to server!", ex); + } + } private void handleDisconnectMessage(ORPGMessage msg){ //TODO: handle notification of rest of ORPG2 system when a client sends a disconnect message @@ -78,6 +109,21 @@ private void handleShutdownMessage(ORPGMessage msg){ //TODO: handle shutdown message from server. (Disconnect from server with special notification about server shutdown) } + + /** + * Observer callback function for network changes. + * @param o NetworkConnectionAlerter object (ignored) + * @param arg NetworkClientState object that contains the new state + */ + @Override + public void update(Observable o, Object arg) { + NetworkClientState ns = (NetworkClientState) arg; + if( ns.isConnection() ){ sendJoinMessage(); } + if( ns.isDisconnect() ){ + ORPGEvent e = new ORPGEvent(this, NetworkClientModule.EVENT_DISCONNECT); + this.modCom.generateEvent(e); //notify other modules of DISCONNECT event. + } + } } Modified: trunk/src/openrpg2/common/core/route/AddressToken.java =================================================================== --- trunk/src/openrpg2/common/core/route/AddressToken.java 2013-09-10 23:56:07 UTC (rev 87) +++ trunk/src/openrpg2/common/core/route/AddressToken.java 2013-09-12 05:55:34 UTC (rev 88) @@ -22,7 +22,13 @@ package openrpg2.common.core.route; /** - * handles addressing messages + * handles addressing messages. + * The default constructor formats a message for delivery to the connected server. + * <i>Long term plans will allow server to server communications between clients. + * Eventually you will be able to send to a server based on a server id value with + * the locally connected server always being referenced with an ID of 0.</i> + * For now all AddressToken.SERVER targets will direct to the connected server + * and simply ignore the ID setting. * @author Snowdog */ public class AddressToken { @@ -57,11 +63,11 @@ private int id; /** - * Creates a new MessageAddress object that is by default set to deliver to a Client with an undeliverable ID. + * Creates a new MessageAddress object that is by default set to deliver to the server with a null ID. */ public AddressToken() { this.exclude = false; - this.target = AddressToken.CLIENT; + this.target = AddressToken.SERVER; this.id = 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sno...@us...> - 2013-09-10 23:56:10
|
Revision: 87 http://sourceforge.net/p/openrpg/svn/87 Author: snowdog_ Date: 2013-09-10 23:56:07 +0000 (Tue, 10 Sep 2013) Log Message: ----------- added event lister+handlers for network connection/disconnect events Modified Paths: -------------- trunk/src/openrpg2/common/core/group/GroupServerModule.java Modified: trunk/src/openrpg2/common/core/group/GroupServerModule.java =================================================================== --- trunk/src/openrpg2/common/core/group/GroupServerModule.java 2013-09-10 23:41:16 UTC (rev 86) +++ trunk/src/openrpg2/common/core/group/GroupServerModule.java 2013-09-10 23:56:07 UTC (rev 87) @@ -26,8 +26,10 @@ import openrpg2.common.core.ORPGMessage; import openrpg2.common.core.engine.InvalidActionRequestException; import openrpg2.common.core.event.ORPGEvent; +import openrpg2.common.core.network.NetworkServerModule; import openrpg2.common.core.route.MessageAddress; import openrpg2.common.core.route.AddressToken; +import openrpg2.common.module.ModuleEventListener; import openrpg2.common.module.NetworkedModule; import openrpg2.common.module.ServerLoadable; @@ -36,7 +38,7 @@ * @author snowdog */ -public class GroupServerModule extends NetworkedModule implements ServerLoadable{ +public class GroupServerModule extends NetworkedModule implements ModuleEventListener, ServerLoadable{ private GroupManager groupManager = null; static final public String ACTION_GET_INFO = "getInfo"; //module Action String static final public int EVENT_GROUPDATA_CHANGED = 1; @@ -53,6 +55,8 @@ protected void doRegistration(){ modCom.registerMessageType(ORPGConstants.TYPE_GROUP, this); modCom.registerEventSender(this, GroupServerModule.EVENT_GROUPDATA_CHANGED); + modCom.registerEventInterest(this, "NetworkServerModule", NetworkServerModule.EVENT_CLIENT_JOIN); + modCom.registerEventInterest(this, "NetworkServerModule", NetworkServerModule.EVENT_CLIENT_DISCONNECT); } /** @@ -192,4 +196,26 @@ } throw new InvalidActionRequestException("No Such Action"); } + + @Override + public void notifyOfModuleEvent(ORPGEvent e) { + switch(e.sourceModuleName){ + case("NetworkServerModule"):{ handleNetworkEvent(e); break;} + } + } + + private void handleNetworkEvent(ORPGEvent e){ + int cid = (int)e.data; + switch(e.id){ + case(NetworkServerModule.EVENT_CLIENT_JOIN):{ + groupManager.clientConnect(cid); + break; + } + case(NetworkServerModule.EVENT_CLIENT_DISCONNECT):{ + groupManager.clientDisconnect(cid); + break; + } + + } + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sno...@us...> - 2013-09-10 23:41:19
|
Revision: 86 http://sourceforge.net/p/openrpg/svn/86 Author: snowdog_ Date: 2013-09-10 23:41:16 +0000 (Tue, 10 Sep 2013) Log Message: ----------- static event identifiers should be public not private Modified Paths: -------------- trunk/src/openrpg2/common/core/network/NetworkServerModule.java Modified: trunk/src/openrpg2/common/core/network/NetworkServerModule.java =================================================================== --- trunk/src/openrpg2/common/core/network/NetworkServerModule.java 2013-09-10 23:33:48 UTC (rev 85) +++ trunk/src/openrpg2/common/core/network/NetworkServerModule.java 2013-09-10 23:41:16 UTC (rev 86) @@ -45,8 +45,8 @@ private final static int OP_ALERT = 3; private final static int OP_SHUTDOWN = 4; - private final static int EVENT_CLIENT_JOIN = 1; - private final static int EVENT_CLIENT_DISCONNECT = 2; + public final static int EVENT_CLIENT_JOIN = 1; + public final static int EVENT_CLIENT_DISCONNECT = 2; private NetworkServer network = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sno...@us...> - 2013-09-10 23:33:52
|
Revision: 85 http://sourceforge.net/p/openrpg/svn/85 Author: snowdog_ Date: 2013-09-10 23:33:48 +0000 (Tue, 10 Sep 2013) Log Message: ----------- Added module catchable events for network activities Modified Paths: -------------- trunk/src/openrpg2/common/core/network/NetworkServerModule.java Modified: trunk/src/openrpg2/common/core/network/NetworkServerModule.java =================================================================== --- trunk/src/openrpg2/common/core/network/NetworkServerModule.java 2013-09-10 23:31:07 UTC (rev 84) +++ trunk/src/openrpg2/common/core/network/NetworkServerModule.java 2013-09-10 23:33:48 UTC (rev 85) @@ -24,12 +24,13 @@ import java.util.Date; import openrpg2.common.core.ORPGConstants; import openrpg2.common.core.ORPGMessage; +import openrpg2.common.core.event.ORPGEvent; import openrpg2.common.module.NetworkedModule; import openrpg2.common.module.ServerLoadable; /** * The NetworkServerModule is a special server loadable module to provide network information to other modules - * in a controled and safe manner. This class is loaded into the module manager and provides an API through which + * in a controlled and safe manner. This class is loaded into the module manager and provides an API through which * network related information can be obtained by other modules and thus keep other modules from relying directly * on the network's specific implementation. This module also provides support for message based requests for * graceful disconnection of/by a client. @@ -39,10 +40,14 @@ private final static String HEADER_OP = "OP"; private final static int OP_NOOP = 0; - private final static int OP_DISCONNECT = 1; - private final static int OP_ALERT = 2; - private final static int OP_SHUTDOWN = 3; + private final static int OP_JOIN = 1; + private final static int OP_DISCONNECT = 2; + private final static int OP_ALERT = 3; + private final static int OP_SHUTDOWN = 4; + private final static int EVENT_CLIENT_JOIN = 1; + private final static int EVENT_CLIENT_DISCONNECT = 2; + private NetworkServer network = null; /** Creates a new instance of NetworkServerModule */ @@ -50,25 +55,39 @@ network = networkReference; } + @Override public void doRegistration(){ - modCom.registerMessageType(ORPGConstants.TYPE_NETWORK, this); + this.modCom.registerMessageType(ORPGConstants.TYPE_NETWORK, this); + this.modCom.registerEventSender(this, NetworkServerModule.EVENT_CLIENT_JOIN); + this.modCom.registerEventSender(this, NetworkServerModule.EVENT_CLIENT_DISCONNECT); } + @Override public void processMessage(ORPGMessage msg){ int clientId = msg.getOriginatorId(); - int operation = Integer.parseInt(msg.getHeader(HEADER_OP)); + int operation = Integer.parseInt(msg.getHeader(NetworkServerModule.HEADER_OP)); switch(operation){ - case(OP_NOOP):{ break; } - case(OP_DISCONNECT):{ handleDisconnectMessage(msg);break; } - case(OP_ALERT):{ handleAlertMessage(msg); break; } - case(OP_SHUTDOWN):{ handleShutdownMessage(msg); break; } + case(NetworkServerModule.OP_NOOP):{ break; } + case(NetworkServerModule.OP_JOIN):{ handleJoinMessage(msg);break; } + case(NetworkServerModule.OP_DISCONNECT):{ handleDisconnectMessage(msg);break; } + case(NetworkServerModule.OP_ALERT):{ handleAlertMessage(msg); break; } + case(NetworkServerModule.OP_SHUTDOWN):{ handleShutdownMessage(msg); break; } default: {break;} } } + private void handleJoinMessage(ORPGMessage msg){ + //Fire an event to all watching modules that the client has joined the server + ORPGEvent e = new ORPGEvent(this,NetworkServerModule.EVENT_CLIENT_JOIN); + e.data = new Integer(msg.getOriginatorId()); + this.modCom.generateEvent(e); + } private void handleDisconnectMessage(ORPGMessage msg){ - //TODO: handle notification of rest of ORPG2 system when a client sends a disconnect message + //Fire an event to all watching modules that the client has disconnected from the server + ORPGEvent e = new ORPGEvent(this,NetworkServerModule.EVENT_CLIENT_DISCONNECT); + e.data = new Integer(msg.getOriginatorId()); + this.modCom.generateEvent(e); } private void handleAlertMessage(ORPGMessage msg){ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sno...@us...> - 2013-09-10 23:31:09
|
Revision: 84 http://sourceforge.net/p/openrpg/svn/84 Author: snowdog_ Date: 2013-09-10 23:31:07 +0000 (Tue, 10 Sep 2013) Log Message: ----------- Fixed minor scope issue Modified Paths: -------------- trunk/src/openrpg2/common/core/event/ORPGEvent.java Modified: trunk/src/openrpg2/common/core/event/ORPGEvent.java =================================================================== --- trunk/src/openrpg2/common/core/event/ORPGEvent.java 2013-09-10 23:13:05 UTC (rev 83) +++ trunk/src/openrpg2/common/core/event/ORPGEvent.java 2013-09-10 23:31:07 UTC (rev 84) @@ -30,7 +30,7 @@ public class ORPGEvent { public int id; public String sourceModuleName; - Object data; + public Object data; public ORPGEvent(){ this.id = 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sno...@us...> - 2013-09-10 23:13:08
|
Revision: 83 http://sourceforge.net/p/openrpg/svn/83 Author: snowdog_ Date: 2013-09-10 23:13:05 +0000 (Tue, 10 Sep 2013) Log Message: ----------- Added JavaDoc information for ORPGMessage object Modified Paths: -------------- trunk/src/openrpg2/common/core/ORPGMessage.java Modified: trunk/src/openrpg2/common/core/ORPGMessage.java =================================================================== --- trunk/src/openrpg2/common/core/ORPGMessage.java 2013-09-10 06:06:24 UTC (rev 82) +++ trunk/src/openrpg2/common/core/ORPGMessage.java 2013-09-10 23:13:05 UTC (rev 83) @@ -83,10 +83,21 @@ data = n.getData(); } - public void setData(byte[] d){ - data = d; + /** + * Sets the binary payload (data) for this message. + * Note: By default the ORPG2 uses a Big-Endian format for its binary + * but as the data will (typically) only be used by a matching receiving module + * the actual endienness of the byte order shouldn't matter generally. + * @param rawData array of bytes + */ + public void setData(byte[] rawData){ + data = rawData; } + /** + * Gets the binary payload (data) for this message. + * @return array of bytes (raw data) + */ public byte[] getData(){ byte[] d = data; if (d == null){ d = new byte[0]; } @@ -98,33 +109,65 @@ NetworkMessage netmsg = new NetworkMessage(this.getEncodedHeaderString(), this.getData()); return netmsg; } - + /** + * Retrieves the identifier for the target module of this message. + * @return Identifier as String + */ public String getHandlerId(){ return new String(handlerId); } + /** + * Sets the identifier of the target module of this message. + * @param handler + */ public void setHandlerId( String handler ){ setHeader(ORPGConstants.MESSAGE_TYPE, handler); handlerId = handler; } + /** + * Get the address this message is being sent too + * @return destination address + */ public MessageAddress getDestination(){ return destination; } + /** + * Sets the destination address for this message. + * @param dest + */ public void setDestination(MessageAddress dest){ destination = dest; } + /** + * Get the connection Identifier of the sender of the message. + * Note: The originator is added/checked by the server to ensure + * messages cannot be faked as belonging to another source. + * @return connection id (int) + */ public int getOriginatorId(){ return originatorId; } + /** + * Sets the connection Identifier of the sender of the message. + * Note: The originator is added/checked by the server to ensure + * messages cannot be faked as belonging to another source. + */ public void setOriginatorId(int sender){ originatorId = sender; } + /** + * Gets the header information for a specific key from this message. + * Header information is stored as key/value pairs + * @param key + * @return value associated with key as string + */ public String getHeader(String key){ String s = ""; if (! header.containsKey(key)){ @@ -142,10 +185,23 @@ return header.keys(); } + /** + * Adds a key/value pair to the header of the message. + * Integer values will be encoded as Strings within the header data + * @param key + * @param number + * @return true if key added, false on error + */ public boolean setHeader(String key, int number){ return setHeader(key, String.valueOf(number)); } + /** + * Adds a key/value pair to the header of the message. + * @param key + * @param value + * @return + */ public boolean setHeader(String key, String value){ try{ header.put(key, value); @@ -157,23 +213,33 @@ } + /** + * Processes the header information into a String for network transmission + * @return String version of header data + */ public String getEncodedHeaderString(){ - return HeaderEncoder.encode(header); //return HeaderEncoder.encodeAsHumanReadable(header); } /** - * This method is called by the routing mechanisims after messaging filters have been applied - * to set a list of client ids that will recieve this message. <b>NOTE: This is an internal method and should not - * be called by programmers directly.</b> - * @param dests int array of client ids to receive a copy of this message. + * This method is called by the routing mechanisms after messaging filters have been applied + * to set a list of client IDs that will receive this message. + * <b>NOTE: This is an internal method and should not be called by programmers directly.</b> + * @param dests array of client IDs to receive a copy of this message. */ public void setFinalRecipientList( int [] dests){ recipients = dests; } + /** + * This method is called by the routing mechanisms after messaging filters have been applied + * to get a list of client IDs that will receive this message. + * <b>NOTE: This is an internal method and should not be called by programmers directly.</b> + * @return array of client IDs to receive a copy of this message. + */ + public int[] getFinalRecipientList(){ return recipients; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sno...@us...> - 2013-09-10 06:06:28
|
Revision: 82 http://sourceforge.net/p/openrpg/svn/82 Author: snowdog_ Date: 2013-09-10 06:06:24 +0000 (Tue, 10 Sep 2013) Log Message: ----------- fixed referencing of static final var Modified Paths: -------------- trunk/src/openrpg2/common/core/group/GroupManager.java Modified: trunk/src/openrpg2/common/core/group/GroupManager.java =================================================================== --- trunk/src/openrpg2/common/core/group/GroupManager.java 2013-09-10 05:21:30 UTC (rev 81) +++ trunk/src/openrpg2/common/core/group/GroupManager.java 2013-09-10 06:06:24 UTC (rev 82) @@ -51,7 +51,7 @@ /** * Counter indexed after each group is added to ensure unique group id numbers */ - private int nextGroupId = LOBBY_ID +1; + private int nextGroupId = GroupManager.LOBBY_ID +1; /** * list of registered groups keyed by group id */ @@ -67,7 +67,7 @@ * @param notifier callback interface reference to gain access to network message arrival announcement */ public GroupManager(NetworkConnectionNotifier notifier) { - addGroup(LOBBY_ID, "Lobby"); + addGroup(GroupManager.LOBBY_ID, "Lobby"); if (notifier != null ){ notifier.registerNetworkConnectionObserver(this); } @@ -247,7 +247,7 @@ */ private void checkGroupRemovable(int id){ Integer gid = new Integer(id); - if( id == LOBBY_ID){ return; } //sanity check; can't remove lobby + if( id == GroupManager.LOBBY_ID){ return; } //sanity check; can't remove lobby if( ! groupList.containsKey(gid)){ return; } //sanity check Group g = (Group) groupList.get(gid); if (g.shouldRemoveGroup() ){ @@ -300,7 +300,7 @@ GroupClient c = new GroupClient(new Integer(id)); addClient(c); GroupMember m = new GroupMember(c); - addMemberToGroup(LOBBY_ID, m); + addMemberToGroup(GroupManager.LOBBY_ID, m); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sno...@us...> - 2013-09-10 05:21:33
|
Revision: 81 http://sourceforge.net/p/openrpg/svn/81 Author: snowdog_ Date: 2013-09-10 05:21:30 +0000 (Tue, 10 Sep 2013) Log Message: ----------- Added module level event handling system. Modified Paths: -------------- trunk/src/openrpg2/common/core/engine/ModuleCommunicator.java trunk/src/openrpg2/common/core/engine/ModuleManager.java trunk/src/openrpg2/common/core/group/GroupServerModule.java trunk/src/openrpg2/server/core/modules/clientlist/ClientList.java Added Paths: ----------- trunk/src/openrpg2/common/core/event/ trunk/src/openrpg2/common/core/event/ModuleEventDispatcher.java trunk/src/openrpg2/common/core/event/ModuleEventManager.java trunk/src/openrpg2/common/core/event/ORPGEvent.java trunk/src/openrpg2/common/module/ModuleEventListener.java Property Changed: ---------------- trunk/src/openrpg2/ Index: trunk/src/openrpg2 =================================================================== --- trunk/src/openrpg2 2013-09-09 22:42:16 UTC (rev 80) +++ trunk/src/openrpg2 2013-09-10 05:21:30 UTC (rev 81) Property changes on: trunk/src/openrpg2 ___________________________________________________________________ Added: svn:ignore ## -0,0 +1 ## +._.DS_Store Modified: trunk/src/openrpg2/common/core/engine/ModuleCommunicator.java =================================================================== --- trunk/src/openrpg2/common/core/engine/ModuleCommunicator.java 2013-09-09 22:42:16 UTC (rev 80) +++ trunk/src/openrpg2/common/core/engine/ModuleCommunicator.java 2013-09-10 05:21:30 UTC (rev 81) @@ -22,8 +22,10 @@ package openrpg2.common.core.engine; import javax.swing.JPanel; +import openrpg2.common.core.event.ORPGEvent; import openrpg2.common.core.ORPGMessage; import openrpg2.common.module.BaseModule; +import openrpg2.common.module.ModuleEventListener; import openrpg2.common.module.NetworkedModule; @@ -43,9 +45,11 @@ public void deregisterGUIComponent(String moduleName); - //core operation interest methods - public void registerOperationInterest(int operationIdentifier, BaseModule reference ); - public void deregisterOperationInterest(int operationIdentifier, BaseModule reference ); + //module event system + public void registerEventSender(BaseModule senderReference, int eventIdentifier); + public void registerEventInterest(ModuleEventListener listener, String fromModule, int eventIdentifier); + public void deregisterEventInterest(ModuleEventListener listener, String fromModule, int eventIdentifier); + public void generateEvent(ORPGEvent e); //runtime methods public void sendToNetwork( ORPGMessage msg ) throws ModuleCommunicationException; Modified: trunk/src/openrpg2/common/core/engine/ModuleManager.java =================================================================== --- trunk/src/openrpg2/common/core/engine/ModuleManager.java 2013-09-09 22:42:16 UTC (rev 80) +++ trunk/src/openrpg2/common/core/engine/ModuleManager.java 2013-09-10 05:21:30 UTC (rev 81) @@ -20,17 +20,20 @@ */ package openrpg2.common.core.engine; +import openrpg2.common.core.event.ModuleEventManager; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JPanel; import openrpg2.common.core.network.NetworkMessageRelay; import openrpg2.common.module.NetworkedModule; import openrpg2.common.core.ORPGConstants; +import openrpg2.common.core.event.ORPGEvent; import openrpg2.common.core.ORPGMessage; import openrpg2.common.core.group.GroupManager; import openrpg2.common.core.gui.GUIManager; import openrpg2.common.core.route.RouteManager; import openrpg2.common.module.BaseModule; +import openrpg2.common.module.ModuleEventListener; /** @@ -54,6 +57,7 @@ private GUIManager guiManager = null; private GroupManager groupManager = null; private RouteManager routeManager = null; + private ModuleEventManager eventManager = new ModuleEventManager(); private Logger log = Logger.getLogger(this.getClass().getName()); @@ -345,16 +349,30 @@ } @Override - public void deregisterOperationInterest(int operationIdentifier, BaseModule moduleReference){ - //TODO + public void registerEventSender(BaseModule senderReference, int eventIdentifier){ + String ref = senderReference.getModuleName(); + this.eventManager.registerEventSender(ref, eventIdentifier); } @Override - public void registerOperationInterest(int operationIdentifier, BaseModule moduleReference){ + public void registerEventInterest(ModuleEventListener listener, String fromModule, int eventIdentifier) { + this.eventManager.registerEventListener(listener, fromModule, eventIdentifier); + } + + @Override + public void deregisterEventInterest(ModuleEventListener listener, String fromModule, int eventIdentifier) { //TODO + //TODO + //TODO + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } - + @Override + public void generateEvent(ORPGEvent e) { + this.eventManager.sendEvent(e); + } + + @Override public Object requestModuleData(String fromModule, String nameOfData ) throws NoSuchModuleException, InvalidDataRequestException{ if ( ! isInitialized() ){ throw new NoSuchModuleException("ModuleManager not initialized. No modules available"); @@ -377,5 +395,5 @@ } return m.performModuleAction(actionName, args); } - + } Added: trunk/src/openrpg2/common/core/event/ModuleEventDispatcher.java =================================================================== --- trunk/src/openrpg2/common/core/event/ModuleEventDispatcher.java (rev 0) +++ trunk/src/openrpg2/common/core/event/ModuleEventDispatcher.java 2013-09-10 05:21:30 UTC (rev 81) @@ -0,0 +1,48 @@ +/* + * ModuleEventDispatcher.java + * + * Author: Snowdog + * Created: September 9, 2013, 4:29 PM + * + * ==================================================================== + * Copyright (C) 2005-2006 The OpenRPG Project (www.openrpg.com) + * + * This program 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. + * + * This software 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 on www.gnu.org for more details. + * ==================================================================== + */ +package openrpg2.common.core.event; + +import openrpg2.common.module.ModuleEventListener; + +/** + * ModuleEventDispatcher handles delivering events between modules. + * Because we cannot determine how long each of the receiving notifyOfModuleEvent + * methods will take before returning we wrap each event dispatch in its own thread. + * Resource wise a bit costly, but it does prevent a module from delaying delivery + * of events to other modules do to long-duration event handling code (ie waiting for + * network data, processing large images, waiting for user response, etc). + * @author snowdog + */ +public class ModuleEventDispatcher implements Runnable { + + private ORPGEvent e; + private ModuleEventListener m; + + public ModuleEventDispatcher(ModuleEventListener m, ORPGEvent e) { + this.e = e; + this.m = m; + } + + @Override + public void run() { + m.notifyOfModuleEvent(e); + } +} \ No newline at end of file Added: trunk/src/openrpg2/common/core/event/ModuleEventManager.java =================================================================== --- trunk/src/openrpg2/common/core/event/ModuleEventManager.java (rev 0) +++ trunk/src/openrpg2/common/core/event/ModuleEventManager.java 2013-09-10 05:21:30 UTC (rev 81) @@ -0,0 +1,125 @@ +/* + * ModuleEventManager.java + * + * Author: Snowdog + * Created: September 9, 2013, 4:20 PM + * + * ==================================================================== + * Copyright (C) 2005-2013 The OpenRPG Project (www.openrpg.com) + * + * This program 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. + * + * This software 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 on www.gnu.org for more details. + * ==================================================================== + */ +package openrpg2.common.core.event; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import openrpg2.common.module.ModuleEventListener; + +/** + * The ModuleEventManager handles the distribution of module generated + * events to all interested modules. ORPGEvents are similar in function + * to the Observer/Observable construct in java allowing one object to monitor + * for changes in another, however as Modules in openrpg2 have NO DIRECT CONTACT + * with any other module the ModuleEventManager (in conjunction with the ORPGEvent + * class) is used to allow Modules to generate events that other interested modules + * can be notified about. Like most event handling systems there is no guarantee + * what order modules will be notified in, only the assurance that all modules that + * have registered an interest in a particular event will be notified when the event + * occurs. + * + * @author snowdog + */ +public class ModuleEventManager { + + private HashMap<String,HashMap> eventMap = null; + + + public ModuleEventManager(){ + this.eventMap = new HashMap<>(); + } + + /** + * Sets up the internal data to receive event notification requests. + * NOTE: Though technically not required this method is called [indirectly] + * by modules that will produce events to make it clear code-wise what event + * notifications the module will provide. + * + * @param moduleName string name of event producing module + * @param eventId numeric id (class constant) of event + */ + public void registerEventSender(String moduleName, int eventId){ + HashMap<Integer,ArrayList> events; + if( this.eventMap.containsKey(moduleName) ){ + events = this.eventMap.get(moduleName); + if( !events.containsKey(eventId)){ + events.put(eventId, null); //will add ArrayList when needed + } + }else{ + events = new HashMap<>(); + events.put(eventId, null); //will add ArrayList when needed + this.eventMap.put(moduleName,events); + } + } + + /** + * Registers a module as a listener (consumer) of events from a given module of a given type. + * @param listener + * @param moduleName Name of module producing the event + * @param eventId Id of the event to listen for + */ + public void registerEventListener(ModuleEventListener listener, String moduleName, int eventId){ + registerEventSender(moduleName,eventId); + HashMap<Integer,ArrayList> events; + ArrayList<ModuleEventListener> watchers; + events = this.eventMap.get(moduleName); + if( events.containsKey(eventId)){ + watchers = events.get(eventId); + + if((watchers != null)&&( !watchers.contains(listener))){ + watchers.add(listener); + } + }else{ + watchers = new ArrayList<>(); + watchers.add(listener); + events.put(eventId, watchers); + } + } + + /** + * Deliver an event to all listening modules. + * Each event is delivered in its own thread to ensure modules will not stall + * the dispatcher. + * @param e + */ + public void sendEvent(ORPGEvent e){ + ArrayList<ModuleEventListener> watchers = getListeners(e.sourceModuleName,e.id); + Iterator<ModuleEventListener> it = watchers.iterator(); + while(it.hasNext()) + { + ModuleEventListener target = it.next(); + Runnable r = new ModuleEventDispatcher(target,e); + new Thread(r).start(); + } + } + + private ArrayList<ModuleEventListener> getListeners(String m, int i){ + HashMap<Integer,ArrayList> events; + ArrayList<ModuleEventListener> watchers = new ArrayList<>(); + events = this.eventMap.get(m); + if( events.containsKey(i)){ + watchers = events.get(i); + } + return watchers; + } + +} Added: trunk/src/openrpg2/common/core/event/ORPGEvent.java =================================================================== --- trunk/src/openrpg2/common/core/event/ORPGEvent.java (rev 0) +++ trunk/src/openrpg2/common/core/event/ORPGEvent.java 2013-09-10 05:21:30 UTC (rev 81) @@ -0,0 +1,60 @@ +/* + * ORPGEvent.java + * + * Author: Snowdog + * Created: September 9, 2013, 4:29 PM + * + * ==================================================================== + * Copyright (C) 2005-2006 The OpenRPG Project (www.openrpg.com) + * + * This program 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. + * + * This software 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 on www.gnu.org for more details. + * ==================================================================== + */ +package openrpg2.common.core.event; + +import openrpg2.common.module.BaseModule; + +/** + * ORPGEvent objects are used to carry event data from the Module that generated + * the event to all 'listening' modules. + * @author snowdog + */ +public class ORPGEvent { + public int id; + public String sourceModuleName; + Object data; + + public ORPGEvent(){ + this.id = 0; + this.sourceModuleName = ""; + this.data = null; + } + + public ORPGEvent(BaseModule sourceModule, int eventId, Object eventData ){ + this.sourceModuleName = sourceModule.getModuleName(); + this.id = eventId; + this.data = eventData; + } + public ORPGEvent(BaseModule sourceModule, int eventId){ + this.sourceModuleName = sourceModule.getModuleName(); + this.id = eventId; + this.data = null; + } + + public boolean hasData(){ + if(this.data != null){ return true; } + return false; + } + + public int id(){ return this.id; } + public String src(){ return this.sourceModuleName; } + +} Modified: trunk/src/openrpg2/common/core/group/GroupServerModule.java =================================================================== --- trunk/src/openrpg2/common/core/group/GroupServerModule.java 2013-09-09 22:42:16 UTC (rev 80) +++ trunk/src/openrpg2/common/core/group/GroupServerModule.java 2013-09-10 05:21:30 UTC (rev 81) @@ -25,6 +25,7 @@ import openrpg2.common.core.ORPGConstants; import openrpg2.common.core.ORPGMessage; import openrpg2.common.core.engine.InvalidActionRequestException; +import openrpg2.common.core.event.ORPGEvent; import openrpg2.common.core.route.MessageAddress; import openrpg2.common.core.route.AddressToken; import openrpg2.common.module.NetworkedModule; @@ -38,6 +39,7 @@ public class GroupServerModule extends NetworkedModule implements ServerLoadable{ private GroupManager groupManager = null; static final public String ACTION_GET_INFO = "getInfo"; //module Action String + static final public int EVENT_GROUPDATA_CHANGED = 1; /** Creates a new instance of GroupServerModule */ public GroupServerModule(GroupManager grpmgr) { @@ -50,6 +52,7 @@ */ protected void doRegistration(){ modCom.registerMessageType(ORPGConstants.TYPE_GROUP, this); + modCom.registerEventSender(this, GroupServerModule.EVENT_GROUPDATA_CHANGED); } /** @@ -84,10 +87,10 @@ private void handleGroupMessage(ORPGMessage msg){ int operation = Integer.parseInt(msg.getHeader(GroupMessageConstants.HEADER_SUB_OP)); switch(operation){ - case(GroupMessageConstants.SUB_OP_ADD):{processCreateGroupRequest(msg); break; } //add a new group - case(GroupMessageConstants.SUB_OP_DROP):{break; } //remove an existing group - case(GroupMessageConstants.SUB_OP_ALTER):{break; } //change group info - case(GroupMessageConstants.SUB_OP_UPDATE):{break; } //refresh/replace group info + case(GroupMessageConstants.SUB_OP_ADD):{sendEventChanged(); processCreateGroupRequest(msg); break; } //add a new group + case(GroupMessageConstants.SUB_OP_DROP):{sendEventChanged(); break; } //remove an existing group + case(GroupMessageConstants.SUB_OP_ALTER):{sendEventChanged(); break; } //change group info + case(GroupMessageConstants.SUB_OP_UPDATE):{sendEventChanged(); break; } //refresh/replace group info default: {break;} } } @@ -100,15 +103,25 @@ private void handleClientMessage(ORPGMessage msg){ int operation = Integer.parseInt(msg.getHeader(GroupMessageConstants.HEADER_SUB_OP)); switch(operation){ - case(GroupMessageConstants.SUB_OP_ADD):{break; } //add a new client - case(GroupMessageConstants.SUB_OP_DROP):{break; } //remove an existing client (disconnect) - case(GroupMessageConstants.SUB_OP_ALTER):{break; } //change client info - case(GroupMessageConstants.SUB_OP_UPDATE):{break; } //refresh/replace client info + case(GroupMessageConstants.SUB_OP_ADD):{ sendEventChanged(); break; } //add a new client + case(GroupMessageConstants.SUB_OP_DROP):{sendEventChanged(); break; } //remove an existing client (disconnect) + case(GroupMessageConstants.SUB_OP_ALTER):{sendEventChanged(); break; } //change client info + case(GroupMessageConstants.SUB_OP_UPDATE):{sendEventChanged(); break; } //refresh/replace client info default: {break;} } } /** + * Constructs an ORPGEvent message to notify other modules that the group + * has changed. + */ + private void sendEventChanged(){ + ORPGEvent e = new ORPGEvent(this,GroupServerModule.EVENT_GROUPDATA_CHANGED); + this.modCom.generateEvent(e); + } + + + /** *processCreateGroupRequest handles requests made by clients for the server *to create a new group. Server will automatically make the requesting client *a GM within the newly created group. Added: trunk/src/openrpg2/common/module/ModuleEventListener.java =================================================================== --- trunk/src/openrpg2/common/module/ModuleEventListener.java (rev 0) +++ trunk/src/openrpg2/common/module/ModuleEventListener.java 2013-09-10 05:21:30 UTC (rev 81) @@ -0,0 +1,34 @@ +/* + * ClientLoadable.java + * + * Author: Snowdog + * Created: September 9, 2013, 7:32 PM + * + * + * ==================================================================== + * Copyright (C) 2005-2006 The OpenRPG Project (www.openrpg.com) + * + * This program 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. + * + * This software 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 on www.gnu.org for more details. + * ==================================================================== + */ +package openrpg2.common.module; + +import openrpg2.common.core.event.ORPGEvent; + +/** + * Modules must implement this interface in order to gain access to + * the inter-module event system. This interface contains the listener method + * that will be called by the event subsystem to pass event data to the module. + * @author snowdog + */ +public interface ModuleEventListener { + public void notifyOfModuleEvent(ORPGEvent e); +} Modified: trunk/src/openrpg2/server/core/modules/clientlist/ClientList.java =================================================================== --- trunk/src/openrpg2/server/core/modules/clientlist/ClientList.java 2013-09-09 22:42:16 UTC (rev 80) +++ trunk/src/openrpg2/server/core/modules/clientlist/ClientList.java 2013-09-10 05:21:30 UTC (rev 81) @@ -24,14 +24,17 @@ import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; +import openrpg2.common.core.event.ORPGEvent; +import openrpg2.common.core.group.GroupServerModule; import openrpg2.common.module.BaseModule; +import openrpg2.common.module.ModuleEventListener; import openrpg2.common.module.ServerLoadable; /** * Server Module for displaying information about currently connected clients. * @author snowdog */ -public class ClientList extends BaseModule implements ServerLoadable{ +public class ClientList extends BaseModule implements ServerLoadable, ModuleEventListener{ public JPanel panel = null; private JTable table = null; @@ -66,7 +69,14 @@ @Override protected void doRegistration() { this.modCom.registerGUIComponent("Client List", panel); + this.modCom.registerEventInterest(this, "GroupSeverModule", GroupServerModule.EVENT_GROUPDATA_CHANGED); } + + @Override + public void notifyOfModuleEvent(ORPGEvent e) { + this.log.info("Got event notification "+e.src()+" i="+e.id); + this.dataSource.updateData(); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sno...@us...> - 2013-09-09 22:42:17
|
Revision: 80 http://sourceforge.net/p/openrpg/svn/80 Author: snowdog_ Date: 2013-09-09 22:42:16 +0000 (Mon, 09 Sep 2013) Log Message: ----------- removed some unused imports Modified Paths: -------------- trunk/src/openrpg2/server/core/ORPGServer.java Modified: trunk/src/openrpg2/server/core/ORPGServer.java =================================================================== --- trunk/src/openrpg2/server/core/ORPGServer.java 2013-09-09 22:15:26 UTC (rev 79) +++ trunk/src/openrpg2/server/core/ORPGServer.java 2013-09-09 22:42:16 UTC (rev 80) @@ -20,15 +20,12 @@ package openrpg2.server.core; -import java.net.InetSocketAddress; import java.util.HashMap; import openrpg2.common.core.logging.DevConsole; import openrpg2.common.core.ORPGConstants; import openrpg2.common.core.engine.Engine; import openrpg2.common.core.logging.SystemLogger; -import openrpg2.common.core.network.NetworkConnection; import openrpg2.common.core.network.NetworkServer; -import openrpg2.common.core.network.NetworkServerModule; import openrpg2.common.util.LogLevelSetter; @@ -42,7 +39,7 @@ public ORPGServer(HashMap argmap) { DevConsole d = new DevConsole(); SystemLogger sysLogger = new SystemLogger(d); - new LogLevelSetter(argmap, sysLogger); + new LogLevelSetter(argmap, sysLogger); //@TODO ignored new object is intentional?! look into this. d.setSystemLoggerCallback(sysLogger); //allows for log level checking in DevConsole d.postSystemInfo(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sno...@us...> - 2013-09-09 22:15:30
|
Revision: 79 http://sourceforge.net/p/openrpg/svn/79 Author: snowdog_ Date: 2013-09-09 22:15:26 +0000 (Mon, 09 Sep 2013) Log Message: ----------- Fixed a bug where AddressToken was created with improper settings. Modified Paths: -------------- trunk/src/openrpg2/common/core/route/AddressToken.java Modified: trunk/src/openrpg2/common/core/route/AddressToken.java =================================================================== --- trunk/src/openrpg2/common/core/route/AddressToken.java 2013-09-09 21:17:10 UTC (rev 78) +++ trunk/src/openrpg2/common/core/route/AddressToken.java 2013-09-09 22:15:26 UTC (rev 79) @@ -55,14 +55,14 @@ private char target; /** id. The identifier for client or group # to use in conjunction with the target. */ private int id; - + /** * Creates a new MessageAddress object that is by default set to deliver to a Client with an undeliverable ID. */ public AddressToken() { - exclude = false; - target = CLIENT; - id = 0; + this.exclude = false; + this.target = AddressToken.CLIENT; + this.id = 0; } /** @@ -70,9 +70,9 @@ * @param id Client ID to deliver message to. */ public AddressToken(int id) { - exclude = false; - target = CLIENT; - id = 0; + this.exclude = false; + this.target = AddressToken.CLIENT; + this.id = 0; this.id = id; } @@ -83,8 +83,8 @@ */ public AddressToken(int id, boolean exclude) { exclude = false; - target = CLIENT; - id = 0; + this.target = AddressToken.CLIENT; + this.id = 0; this.id = id; this.exclude = exclude; } @@ -96,8 +96,8 @@ */ public AddressToken(char target, int id) { exclude = false; - target = CLIENT; - id = 0; + this.target = AddressToken.CLIENT; + this.id = 0; if (isValidTarget(target)){ this.target = target; } @@ -208,15 +208,15 @@ * @return boolean. true if target is valid. */ private boolean isValidTarget(char target){ - if ( target == BROADCAST){return true;} - if ( target == SERVER){return true;} - if ( target == ALL ){return true;} - if ( target == GM ){return true;} - if ( target == PLAYERS ){return true;} - if ( target == LURKERS ){return true;} - if ( target == INVISIBLES ){return true;} - if ( target == SELF ){return true;} - if ( target == CLIENT ){return true;} + if ( target == AddressToken.BROADCAST){return true;} + if ( target == AddressToken.SERVER){return true;} + if ( target == AddressToken.ALL ){return true;} + if ( target == AddressToken.GM ){return true;} + if ( target == AddressToken.PLAYERS ){return true;} + if ( target == AddressToken.LURKERS ){return true;} + if ( target == AddressToken.INVISIBLES ){return true;} + if ( target == AddressToken.SELF ){return true;} + if ( target == AddressToken.CLIENT ){return true;} return false; } @@ -227,10 +227,18 @@ */ public String getHumanReadableAddress(){ String temp = "Address: "; - if ( target == BROADCAST ){temp += "To BROADCAST (all clients)"; return temp;} - if ( target == SERVER){ temp += "SERVER only"; return temp; } + if ( target == AddressToken.BROADCAST ){temp += "To BROADCAST (all clients)"; return temp;} + if ( target == AddressToken.SERVER){ temp += "SERVER only"; return temp; } if (exclude){ temp += "Exclude "; } else {temp += "To ";} - if ( target == ALL ){temp += "ALL in group #";} else if ( target == CLIENT ){temp += "CLIENT #";} else if ( target == GM ){temp += "GMs in group #";} else if ( target == PLAYERS ){temp += "PLAYERS in group #";} else if ( target == LURKERS ){temp += "LURKERS in group #";} else if ( target == INVISIBLES ){temp += "INVISIBLES in group #";} else if ( target == SELF ){temp += "SELF in group # ";} else{ temp += "[invalid address]"; return temp;} + + if ( target == ALL ){temp += "ALL in group #";} + else if ( target == AddressToken.CLIENT ){temp += "CLIENT #";} + else if ( target == AddressToken.GM ){temp += "GMs in group #";} + else if ( target == AddressToken.PLAYERS ){temp += "PLAYERS in group #";} + else if ( target == AddressToken.LURKERS ){temp += "LURKERS in group #";} + else if ( target == AddressToken.INVISIBLES ){temp += "INVISIBLES in group #";} + else if ( target == SELF ){temp += "SELF in group # ";} + else{ temp += "[invalid address]"; return temp;} temp += id; return temp; @@ -248,17 +256,17 @@ static public AddressToken convert(String addressToken) throws InvalidMessageTargetException { AddressToken temp = new AddressToken(); int pos = 0; - if (addressToken.charAt(pos) == BROADCAST){ - temp.setTarget(BROADCAST); + if (addressToken.charAt(pos) == AddressToken.BROADCAST){ + temp.setTarget(AddressToken.BROADCAST); temp.setId(0); return temp; } - if (addressToken.charAt(pos) == SERVER){ - temp.setTarget(SERVER); + if (addressToken.charAt(pos) == AddressToken.SERVER){ + temp.setTarget(AddressToken.SERVER); temp.setId(0); return temp; } - if (addressToken.charAt(pos) == NOT){ + if (addressToken.charAt(pos) == AddressToken.NOT){ temp.setExcluded(true); pos++; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sno...@us...> - 2013-09-09 21:17:13
|
Revision: 78 http://sourceforge.net/p/openrpg/svn/78 Author: snowdog_ Date: 2013-09-09 21:17:10 +0000 (Mon, 09 Sep 2013) Log Message: ----------- Updated to show current version info in title bar of main window Modified Paths: -------------- trunk/src/openrpg2/common/core/gui/mdi/MDIFrame.java Modified: trunk/src/openrpg2/common/core/gui/mdi/MDIFrame.java =================================================================== --- trunk/src/openrpg2/common/core/gui/mdi/MDIFrame.java 2013-09-09 20:49:33 UTC (rev 77) +++ trunk/src/openrpg2/common/core/gui/mdi/MDIFrame.java 2013-09-09 21:17:10 UTC (rev 78) @@ -42,7 +42,7 @@ * Creates a new instance of MDIFrame */ public MDIFrame() { - super(ORPGConstants.OPENRPG2_NAME); + super(ORPGConstants.getVersionString()); mainPane=new JDesktopPane(); setSize(500,400); getContentPane().add(mainPane); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sno...@us...> - 2013-09-09 20:49:35
|
Revision: 77 http://sourceforge.net/p/openrpg/svn/77 Author: snowdog_ Date: 2013-09-09 20:49:33 +0000 (Mon, 09 Sep 2013) Log Message: ----------- Javadoc clarification Modified Paths: -------------- trunk/src/openrpg2/common/module/NetworkedModule.java Modified: trunk/src/openrpg2/common/module/NetworkedModule.java =================================================================== --- trunk/src/openrpg2/common/module/NetworkedModule.java 2013-09-09 05:28:04 UTC (rev 76) +++ trunk/src/openrpg2/common/module/NetworkedModule.java 2013-09-09 20:49:33 UTC (rev 77) @@ -27,9 +27,14 @@ /** * The NetworkedModule is derived from BaseModule and adds support for registering the module - * to send and recieve messages from the OpenRPG2 network subsystem. Access to OpenRPG network + * to send and receive messages from the OpenRPG2 network subsystem. Access to OpenRPG network * services is not required by modules however developers interested in using network services * should derive their own modules from NetworkedModule instead of BaseModule to gain network access. + * + * <i>Note: the reason this is a class extended from BaseModule and not simply an + * interface is to insure that all hooks handed to the network code are actually + * OpenRPG2 Modules.</i> + * * @author snowdog * @see BaseModule */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |