[AdminConsole] Added the possibility to end user session without kicking him/her off. Fixed bug with discarding row selection in user table

This commit is contained in:
magenoxx 2014-04-28 18:21:55 +05:30
parent 44ee670baf
commit 74ddaa4a57
8 changed files with 159 additions and 99 deletions

View file

@ -146,6 +146,7 @@ public interface MageServer {
//admin methods
List<UserView> getUsers(String sessionId) throws MageException;
void disconnectUser(String sessionId, String userSessionId) throws MageException;
void endUserSession(String sessionId, String userSessionId) throws MageException;
void removeTable(String sessionId, UUID tableId) throws MageException;
void sendBroadcastMessage(String sessionId, String message) throws MageException;
}

View file

@ -28,18 +28,6 @@
package mage.remote;
import java.net.Authenticator;
import java.net.ConnectException;
import java.net.MalformedURLException;
import java.net.PasswordAuthentication;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import mage.MageException;
import mage.cards.decks.DeckCardLists;
import mage.cards.decks.InvalidDeckException;
@ -56,22 +44,9 @@ import mage.interfaces.MageServer;
import mage.interfaces.ServerState;
import mage.interfaces.callback.ClientCallback;
import mage.utils.CompressUtil;
import mage.view.DraftPickView;
import mage.view.GameTypeView;
import mage.view.MatchView;
import mage.view.TableView;
import mage.view.TournamentTypeView;
import mage.view.TournamentView;
import mage.view.UserDataView;
import mage.view.UserView;
import mage.view.UsersView;
import mage.view.*;
import org.apache.log4j.Logger;
import org.jboss.remoting.CannotConnectException;
import org.jboss.remoting.Client;
import org.jboss.remoting.ConnectionListener;
import org.jboss.remoting.ConnectionValidator;
import org.jboss.remoting.InvokerLocator;
import org.jboss.remoting.Remoting;
import org.jboss.remoting.*;
import org.jboss.remoting.callback.Callback;
import org.jboss.remoting.callback.HandleCallbackException;
import org.jboss.remoting.callback.InvokerCallbackHandler;
@ -79,6 +54,9 @@ import org.jboss.remoting.transport.bisocket.Bisocket;
import org.jboss.remoting.transport.socket.SocketWrapper;
import org.jboss.remoting.transporter.TransporterClient;
import java.net.*;
import java.util.*;
/**
*
* @author BetaSteward_at_googlemail.com
@ -1244,6 +1222,21 @@ public class SessionImpl implements Session {
return false;
}
@Override
public boolean endUserSession(String userSessionId) {
try {
if (isConnected()) {
server.endUserSession(sessionId, userSessionId);
return true;
}
} catch (MageException ex) {
handleMageException(ex);
} catch (Throwable t) {
handleThrowable(t);
}
return false;
}
private void handleThrowable(Throwable t) {
logger.fatal("Communication error", t);
sessionState = SessionState.SERVER_UNAVAILABLE;

View file

@ -27,7 +27,6 @@
*/
package mage.remote.interfaces;
import java.util.UUID;
import mage.remote.Connection;
/**
@ -48,6 +47,8 @@ public interface Connect {
boolean isConnected();
boolean disconnectUser(String userSessionId);
boolean endUserSession(String userSessionId);
String getSessionId();
}

View file

@ -1,4 +1,4 @@
<?xml version="1.1" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<AuxValues>
@ -21,7 +21,7 @@
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jSplitPane1" alignment="1" pref="395" max="32767" attributes="0"/>
<Component id="jSplitPane1" alignment="1" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
@ -69,7 +69,7 @@
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane1" alignment="0" pref="360" max="32767" attributes="0"/>
<Component id="jScrollPane1" alignment="0" pref="358" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
@ -101,16 +101,21 @@
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="btnDisconnect" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="164" max="32767" attributes="0"/>
<Component id="btnDisconnect" min="-2" pref="103" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="btnEndSession" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="8" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="btnDisconnect" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="10" max="32767" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="btnDisconnect" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnEndSession" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -124,6 +129,14 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnDisconnectActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="btnEndSession">
<Properties>
<Property name="text" type="java.lang.String" value="End session"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnEndSessionActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
</SubComponents>
@ -139,7 +152,7 @@
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jPanel5" alignment="0" max="32767" attributes="0"/>
<Component id="jPanel6" alignment="0" max="32767" attributes="0"/>
<Component id="jPanel6" alignment="0" pref="301" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
@ -163,7 +176,7 @@
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane2" alignment="0" pref="359" max="32767" attributes="0"/>
<Component id="jScrollPane2" alignment="0" pref="356" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
@ -192,27 +205,27 @@
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="btnDelete" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="235" max="32767" attributes="0"/>
<Component id="btnRemoveTable" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="170" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="btnDelete" min="-2" max="-2" attributes="0"/>
<Component id="btnRemoveTable" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JButton" name="btnDelete">
<Component class="javax.swing.JButton" name="btnRemoveTable">
<Properties>
<Property name="text" type="java.lang.String" value="Remove"/>
<Property name="label" type="java.lang.String" value="Remove Table"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnDeleteActionPerformed"/>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnRemoveTableActionPerformed"/>
</Events>
</Component>
</SubComponents>

View file

@ -33,18 +33,18 @@
*/
package mage.server.console;
import mage.remote.Session;
import mage.view.TableView;
import mage.view.UserView;
import org.apache.log4j.Logger;
import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import javax.swing.SwingWorker;
import javax.swing.table.AbstractTableModel;
import mage.remote.Session;
import mage.view.TableView;
import mage.view.UserView;
import org.apache.log4j.Logger;
/**
*
@ -113,12 +113,13 @@ public class ConsolePanel extends javax.swing.JPanel {
tblUsers = new javax.swing.JTable();
jPanel4 = new javax.swing.JPanel();
btnDisconnect = new javax.swing.JButton();
btnEndSession = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
jPanel5 = new javax.swing.JPanel();
jScrollPane2 = new javax.swing.JScrollPane();
tblTables = new javax.swing.JTable();
jPanel6 = new javax.swing.JPanel();
btnDelete = new javax.swing.JButton();
btnRemoveTable = new javax.swing.JButton();
jSplitPane1.setDividerLocation(250);
jSplitPane1.setResizeWeight(0.5);
@ -134,7 +135,7 @@ public class ConsolePanel extends javax.swing.JPanel {
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 358, Short.MAX_VALUE)
);
jPanel4.setVerifyInputWhenFocusTarget(false);
@ -146,19 +147,30 @@ public class ConsolePanel extends javax.swing.JPanel {
}
});
btnEndSession.setText("End session");
btnEndSession.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnEndSessionActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addComponent(btnDisconnect)
.addContainerGap(164, Short.MAX_VALUE))
.addComponent(btnDisconnect, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(btnEndSession)
.addContainerGap(8, Short.MAX_VALUE))
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addComponent(btnDisconnect)
.addContainerGap(10, Short.MAX_VALUE))
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnDisconnect)
.addComponent(btnEndSession))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
@ -189,13 +201,13 @@ public class ConsolePanel extends javax.swing.JPanel {
);
jPanel5Layout.setVerticalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 359, Short.MAX_VALUE)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 356, Short.MAX_VALUE)
);
btnDelete.setText("Remove");
btnDelete.addActionListener(new java.awt.event.ActionListener() {
btnRemoveTable.setLabel("Remove Table");
btnRemoveTable.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnDeleteActionPerformed(evt);
btnRemoveTableActionPerformed(evt);
}
});
@ -204,13 +216,13 @@ public class ConsolePanel extends javax.swing.JPanel {
jPanel6Layout.setHorizontalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addComponent(btnDelete)
.addContainerGap(235, Short.MAX_VALUE))
.addComponent(btnRemoveTable)
.addContainerGap(170, Short.MAX_VALUE))
);
jPanel6Layout.setVerticalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addComponent(btnDelete)
.addComponent(btnRemoveTable)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
@ -219,7 +231,7 @@ public class ConsolePanel extends javax.swing.JPanel {
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, 301, Short.MAX_VALUE)
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@ -239,7 +251,7 @@ public class ConsolePanel extends javax.swing.JPanel {
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSplitPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 395, Short.MAX_VALUE)
.addComponent(jSplitPane1, javax.swing.GroupLayout.Alignment.TRAILING)
);
}// </editor-fold>//GEN-END:initComponents
@ -248,14 +260,20 @@ public class ConsolePanel extends javax.swing.JPanel {
ConsoleFrame.getSession().disconnectUser((String)tableUserModel.getValueAt(row, 3));
}//GEN-LAST:event_btnDisconnectActionPerformed
private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed
private void btnRemoveTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveTableActionPerformed
int row = this.tblTables.getSelectedRow();
ConsoleFrame.getSession().removeTable((UUID)tableTableModel.getValueAt(row, 7));
}//GEN-LAST:event_btnDeleteActionPerformed
}//GEN-LAST:event_btnRemoveTableActionPerformed
private void btnEndSessionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEndSessionActionPerformed
int row = this.tblUsers.getSelectedRow();
ConsoleFrame.getSession().endUserSession((String) tableUserModel.getValueAt(row, 3));
}//GEN-LAST:event_btnEndSessionActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnDelete;
private javax.swing.JButton btnDisconnect;
private javax.swing.JButton btnEndSession;
private javax.swing.JButton btnRemoveTable;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
@ -399,6 +417,7 @@ class UpdateUsersTask extends SwingWorker<Void, List<UserView>> {
private Session session;
private ConsolePanel panel;
private List<UserView> previousUsers;
private static final Logger logger = Logger.getLogger(UpdateUsersTask.class);
@ -410,12 +429,42 @@ class UpdateUsersTask extends SwingWorker<Void, List<UserView>> {
@Override
protected Void doInBackground() throws Exception {
while (!isCancelled()) {
this.publish(session.getUsers());
List<UserView> users = session.getUsers();
if (previousUsers == null || checkUserListChanged(users)) {
logger.debug("Need to update the user list");
this.publish(users);
previousUsers = users;
}
Thread.sleep(1000);
}
return null;
}
private boolean checkUserListChanged(List<UserView> usersToCheck) {
if (previousUsers == null || usersToCheck == null) {
return true;
}
if (previousUsers.size() != usersToCheck.size()) {
// new user appeared
return true;
}
for (UserView u1 : previousUsers) {
boolean found = false;
for (UserView u2 : usersToCheck) {
if (u1.getUserName().equals(u2.getUserName())) {
found = true;
break;
}
}
if (!found) {
// some new user replaced old one
return true;
}
}
// seems nothing has been changed
return false;
}
@Override
protected void process(List<List<UserView>> view) {
panel.update(view.get(0));

View file

@ -28,11 +28,6 @@
package mage.server;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import mage.MageException;
import mage.cards.decks.DeckCardLists;
import mage.cards.repository.CardInfo;
@ -51,13 +46,7 @@ import mage.interfaces.callback.ClientCallback;
import mage.remote.MageVersionException;
import mage.server.draft.CubeFactory;
import mage.server.draft.DraftManager;
import mage.server.game.DeckValidatorFactory;
import mage.server.game.GameFactory;
import mage.server.game.GameManager;
import mage.server.game.GamesRoom;
import mage.server.game.GamesRoomManager;
import mage.server.game.PlayerFactory;
import mage.server.game.ReplayManager;
import mage.server.game.*;
import mage.server.services.LogKeys;
import mage.server.services.impl.FeedbackServiceImpl;
import mage.server.services.impl.LogServiceImpl;
@ -66,23 +55,17 @@ import mage.server.tournament.TournamentManager;
import mage.server.util.ConfigSettings;
import mage.server.util.ServerMessagesUtil;
import mage.server.util.ThreadExecutor;
import mage.utils.ActionWithBooleanResult;
import mage.utils.ActionWithNullNegativeResult;
import mage.utils.ActionWithTableViewResult;
import mage.utils.CompressUtil;
import mage.utils.MageVersion;
import mage.view.ChatMessage;
import mage.utils.*;
import mage.view.*;
import mage.view.ChatMessage.MessageColor;
import mage.view.DraftPickView;
import mage.view.GameView;
import mage.view.MatchView;
import mage.view.TableView;
import mage.view.TournamentView;
import mage.view.UserDataView;
import mage.view.UserView;
import mage.view.UsersView;
import org.apache.log4j.Logger;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
/**
*
* @author BetaSteward_at_googlemail.com, noxx
@ -920,6 +903,16 @@ public class MageServerImpl implements MageServer {
});
}
@Override
public void endUserSession(final String sessionId, final String userSessionId) throws MageException {
execute("endUserSession", sessionId, new Action() {
@Override
public void execute() {
SessionManager.getInstance().endUserSession(sessionId, userSessionId);
}
});
}
@Override
public void removeTable(final String sessionId, final UUID tableId) throws MageException {
execute("removeTable", sessionId, new Action() {

View file

@ -27,9 +27,6 @@
*/
package mage.server;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import mage.MageException;
import mage.server.services.LogKeys;
import mage.server.services.impl.LogServiceImpl;
@ -37,6 +34,10 @@ import mage.view.UserDataView;
import org.apache.log4j.Logger;
import org.jboss.remoting.callback.InvokerCallbackHandler;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
*
* @author BetaSteward_at_googlemail.com
@ -134,6 +135,13 @@ public class SessionManager {
}
}
public void endUserSession(String sessionId, String userSessionId) {
if (isAdmin(sessionId)) {
disconnect(userSessionId, false);
LogServiceImpl.instance.log(LogKeys.KEY_SESSION_END_BY_ADMIN, sessionId, userSessionId);
}
}
public boolean isAdmin(String sessionId) {
Session admin = sessions.get(sessionId);
if (admin != null) {

View file

@ -17,6 +17,8 @@ public interface LogKeys {
String KEY_SESSION_DISCONNECTED_BY_ADMIN = "sessionDisconnectedByAdmin";
String KEY_SESSION_END_BY_ADMIN = "sessionEndSessionByAdmin";
String KEY_NOT_VALID_SESSION = "sessionNotValid";
String KEY_NOT_VALID_SESSION_INTERNAL = "sessionNotValidInternal";