changeset 103:caea2e66deb8

*** empty log message ***
author pin
date Sat, 22 Dec 2007 19:26:25 +0900
parents 1773abed1fc8
children 91f053bdfb18
files export/sessionmanager.jar rep/SessionManager.java
diffstat 2 files changed, 42 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
Binary file export/sessionmanager.jar has changed
--- a/rep/SessionManager.java	Sat Dec 22 17:42:51 2007 +0900
+++ b/rep/SessionManager.java	Sat Dec 22 19:26:25 2007 +0900
@@ -502,25 +502,51 @@
 	}
 
 	public void ActionOccured(REPActionEvent event) {
-		System.out.println("Action!");
-		SocketChannel editorChannel = event.getEditorChannel();
+
+//		SocketChannel editorChannel = event.getEditorChannel();
+//		int sid = event.getSID();
+//		Editor editor = new Editor(editorChannel);
+//		editor.setHost(this.myHost);
+//		Session session = sessionlist.getSession(sid);
+//		session.addEditor(editor);
+//		
+//		Editor owner = session.getMaster();
+//		
+//		REPCommand command = new REPCommand();
+//		command.setCMD(REP.SMCMD_SELECT);
+//		command.setSID(sid);
+//		command.setString(editor.getHost() + ":" + editor.getPort());
+//		owner.send(command);
+		
+		/***  ***/
+		SocketChannel channel = event.getEditorChannel();
 		int sid = event.getSID();
-		//int eid = 0;
-		//int eid = event.getEID(); 
-		//sessionlist.addEditor(editorChannel, sid, eid);
-		Editor editor = new Editor(editorChannel);
-		editor.setHost(this.myHost);
 		Session session = sessionlist.getSession(sid);
-		session.addEditor(editor);
-		
-		Editor master = session.getMaster();
+		if(session.isOwner()){
+			int eid = session.addEditor(new Editor(channel));
+			REPCommand sendCommand = new REPCommand();
+			sendCommand.setCMD(REP.SMCMD_JOIN_ACK);
+			sendCommand.setEID(eid);
+			sendCommand.setSID(sid);
+			REPPacketSend sender = new REPPacketSend(channel);
+			sender.send(sendCommand);
+		}else {
+			SocketChannel editorChannel = event.getEditorChannel();
+			sid = event.getSID();
+			Editor editor = new Editor(editorChannel);
+			editor.setHost(this.myHost);
+			session = sessionlist.getSession(sid);
+			session.addEditor(editor);
+			
+			Editor owner = session.getMaster();
+			
+			REPCommand command = new REPCommand();
+			command.setCMD(REP.SMCMD_SELECT);
+			command.setSID(sid);
+			command.setString(editor.getHost() + ":" + editor.getPort());
+			owner.send(command);
+		}
 		
-		REPCommand command = new REPCommand();
-		command.setCMD(REP.SMCMD_SELECT);
-		command.setSID(sid);
-		command.setString(editor.getHost() + ":" + editor.getPort());
-		
-		master.send(command);
 		
 		//REPPacketSend send = new REPPacketSend(editorChannel);
 		//send.send(new REPCommand(REP.SMCMD_SELECT_ACK, sid, eid, 0,0,0,""));