Changeset c09e0ade840ad0e35f7951d03b2345b8e458d93d

Show
Ignore:
Timestamp:
05/18/08 14:13:11 (5 months ago)
Author:
Christopher Jung <bktheg@web.de>
git-committer:
Christopher Jung <bktheg@web.de> 1211112791 +0200
git-parent:

[aef156152991f65fcb92f36f5cad0fc2c6a704d1]

git-author:
Christopher Jung <bktheg@web.de> 1211112791 +0200
Message:

[ref] Sessionverwaltung auf Java-Sessions umgestellt

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • db/tables/users.sql

    re65784f rc09e0ad  
    3535  `knownItems` text NOT NULL default '', 
    3636  `version` int(10) unsigned not null default '0', 
     37  `blocked` tinyint(1) unsigned not null default '0', 
    3738  PRIMARY KEY  (`id`), 
    3839  KEY `ally` (`ally`), 
  • db/updates.xml

    r29e34b0 rc09e0ad  
    501501                alter table logging modify type varchar(15) not null; 
    502502        ]]></update> 
     503        <update type="structure" datum="2008-05-17"><![CDATA[ 
     504                alter table users add blocked tinyint(1) unsigned not null default '0'; 
     505        ]]></update> 
    503506</updates> 
  • src/META-INF/services/net.driftingsouls.ds2.server.framework.authentication.LoginEventListener

    r47cd40b rc09e0ad  
    11net.driftingsouls.ds2.server.user.authentication.VacationCheckLoginEventListener 
     2net.driftingsouls.ds2.server.user.authentication.TickBlockLoginEventListener 
  • src/net/driftingsouls/ds2/server/ContextCommon.java

    r28b2039 rc09e0ad  
    2727import net.driftingsouls.ds2.server.framework.Context; 
    2828import net.driftingsouls.ds2.server.framework.ContextInstance; 
     29import net.driftingsouls.ds2.server.framework.ContextMap; 
    2930import net.driftingsouls.ds2.server.scripting.ScriptParserContext; 
    3031 
     
    3334 * @author Christopher Jung 
    3435 */ 
    35 @ContextInstance(ContextInstance.Type.SINGLETON
     36@ContextInstance(ContextInstance.Scope.REQUEST
    3637public class ContextCommon { 
    3738        private Context context = null; 
     
    3940        /** 
    4041         * Konstruktur - Wird vom Kontext aufgerufen 
    41          * @param context Der Kontext, an den die Instanz gebunden werden soll 
    4242         */ 
    43         public ContextCommon(Context context) { 
    44                 this.context = context
     43        public ContextCommon() { 
     44                this.context = ContextMap.getContext()
    4545        } 
    4646 
  • src/net/driftingsouls/ds2/server/entities/User.java

    r65e6cfe rc09e0ad  
    193193        private int lostShips; 
    194194        private String knownItems; 
     195        private boolean blocked = false; 
    195196         
    196197        @Transient 
     
    10061007                this.wait4vac = value; 
    10071008        } 
     1009         
     1010        /** 
     1011         * Gibt zurueck, ob der User wegen einer Tickberechnung kurzzeitig blockiert wird 
     1012         * @return <code>true</code>, falls er geblockt wird 
     1013         */ 
     1014        public boolean isBlocked() { 
     1015                return this.blocked; 
     1016        } 
     1017         
     1018        /** 
     1019         * Setzt, ob der User wegen einer Tickberechnung kurzzeitig geblockt wird 
     1020         * @param blocked <code>true</code>, falls er geblockt wird 
     1021         */ 
     1022        public void setBlocked(boolean blocked) { 
     1023                this.blocked = blocked; 
     1024        } 
    10081025} 
  • src/net/driftingsouls/ds2/server/framework/BasicContext.java

    r5dc487d rc09e0ad  
    1919package net.driftingsouls.ds2.server.framework; 
    2020 
    21 import java.lang.reflect.Constructor; 
    2221import java.util.ArrayList; 
    2322import java.util.HashMap; 
     
    185184        @SuppressWarnings("unchecked") 
    186185        public <T> T get(Class<T> cls) { 
     186                if( !cls.isAnnotationPresent(ContextInstance.class) ) { 
     187                        LOG.fatal("ContextInstance Annotation not present: "+cls.getName()); 
     188                        return null; 
     189                } 
     190                 
     191                ContextInstance.Scope scope = cls.getAnnotation(ContextInstance.class).value(); 
     192                 
    187193                /* TODO: Exceptions? */ 
    188                 if( !contextSingletons.containsKey(cls) )  { 
    189                         if( !cls.isAnnotationPresent(ContextInstance.class) ) { 
    190                                 LOG.fatal("ContextInstance Annotation not present: "+cls.getName()); 
    191                                 return null; 
    192                         } 
    193                         if( cls.getAnnotation(ContextInstance.class).value() != ContextInstance.Type.SINGLETON ) { 
    194                                 LOG.fatal("Context-Class is not a singleton: "+cls.getName()); 
    195                                 return null; 
    196                         } 
    197                         try { 
    198                                 Constructor<T> cons = cls.getConstructor(Context.class); 
    199                                 contextSingletons.put(cls, cons.newInstance(this)); 
    200                         } 
    201                         catch( Exception e ) { 
    202                                 LOG.error(e,e); 
    203                                 return null; 
    204                         } 
    205                 } 
    206  
    207                 return (T)contextSingletons.get(cls); 
     194                if( scope == ContextInstance.Scope.REQUEST ) { 
     195                        if( !contextSingletons.containsKey(cls) )  { 
     196                                try { 
     197                                        contextSingletons.put(cls, cls.newInstance()); 
     198                                } 
     199                                catch( Exception e ) { 
     200                                        LOG.error(e,e); 
     201                                        return null; 
     202                                } 
     203                        } 
     204                         
     205                        return (T)contextSingletons.get(cls); 
     206                } 
     207                 
     208                return this.request.getFromSession(cls); 
    208209        } 
    209210 
     
    241242                this.listener.add(listener); 
    242243        } 
     244 
     245        public void remove(Class<?> cls) { 
     246                if( !cls.isAnnotationPresent(ContextInstance.class) ) { 
     247                        LOG.fatal("ContextInstance Annotation not present: "+cls.getName()); 
     248                        return; 
     249                } 
     250                 
     251                ContextInstance.Scope scope = cls.getAnnotation(ContextInstance.class).value(); 
     252                if( scope == ContextInstance.Scope.REQUEST ) { 
     253                        this.contextSingletons.remove(cls); 
     254                } 
     255                else { 
     256                        this.request.removeFromSession(cls); 
     257                } 
     258        } 
    243259} 
  • src/net/driftingsouls/ds2/server/framework/BasicUser.java

    r65e6cfe rc09e0ad  
    9898        /** 
    9999         * Fuegt dem Benutzer weitere Sessiondaten hinzu 
    100          * @param sessiondata Die Sessiondaten 
    101          */ 
    102         public void setSessionData(Session sessiondata) { 
    103                 if( (sessiondata != null) && !sessiondata.getUseGfxPak() ) { 
     100         * @param useGfxPak <code>true</code>, falls ein Grafikpak genutzt werden soll 
     101         */ 
     102        public void setSessionData(boolean useGfxPak) { 
     103                if( !useGfxPak ) { 
    104104                        forceDefaultImgPath = true; 
    105105                } 
  • src/net/driftingsouls/ds2/server/framework/CmdLineRequest.java

    r283e6c7 rc09e0ad  
    2929 
    3030import org.apache.commons.fileupload.FileItem; 
     31import org.apache.commons.logging.Log; 
     32import org.apache.commons.logging.LogFactory; 
    3133 
    3234/** 
     
    3638 */ 
    3739public class CmdLineRequest implements Request { 
     40        private Log log = LogFactory.getLog(CmdLineRequest.class); 
     41         
    3842        private Map<String,String> params = new HashMap<String,String>(); 
    3943         
     
    131135        } 
    132136 
     137        public <T> T getFromSession(Class<T> cls) { 
     138                log.error("getFromSession not supported"); 
     139                 
     140                return null; 
     141        } 
     142 
     143        public void removeFromSession(Class<?> cls) { 
     144                log.error("removeFromSession not supported"); 
     145        } 
     146 
    133147} 
  • src/net/driftingsouls/ds2/server/framework/Context.java

    r9ee106f rc09e0ad  
    4242         * @return Eine Database-Instanz 
    4343         */ 
    44         public abstract Database getDatabase(); 
     44        public Database getDatabase(); 
    4545         
    4646        /** 
     
    4848         * @return Die DB-Session 
    4949         */ 
    50         public abstract org.hibernate.Session getDB(); 
     50        public org.hibernate.Session getDB(); 
    5151         
    5252        /** 
     
    7272         * @return Eine Liste mit dem Ergebnis 
    7373         */ 
    74         public abstract <T> List<T> query(String query, Class<T> classType); 
     74        public <T> List<T> query(String query, Class<T> classType); 
    7575 
    7676        /** 
     
    7979         * @return Das zum gerade aktiven User gehoerende User-Objekt 
    8080         */ 
    81         public abstract BasicUser getActiveUser(); 
     81        public BasicUser getActiveUser(); 
    8282 
    8383        /** 
     
    8686         * @param user Der neue aktive User 
    8787         */ 
    88         public abstract void setActiveUser(BasicUser user); 
     88        public void setActiveUser(BasicUser user); 
    8989 
    9090        /** 
     
    9393         * @param error Die Beschreibung des Fehlers 
    9494         */ 
    95         public abstract void addError(String error); 
     95        public void addError(String error); 
    9696 
    9797        /** 
     
    101101         * @param link Die Ausweich-URL 
    102102         */ 
    103         public abstract void addError(String error, String link); 
     103        public void addError(String error, String link); 
    104104 
    105105        /** 
     
    111111         * @see #addError(String) 
    112112         */ 
    113         public abstract Error getLastError(); 
     113        public Error getLastError(); 
    114114 
    115115        /** 
     
    118118         * @return Eine Liste aller Fehlerbeschreibungen  
    119119         */ 
    120         public abstract Error[] getErrorList(); 
     120        public Error[] getErrorList(); 
    121121         
    122122        /** 
     
    124124         * @return Die Request des Aufrufs 
    125125         */ 
    126         public abstract Request getRequest(); 
     126        public Request getRequest(); 
    127127         
    128128        /** 
     
    130130         * @return Die Response des Aufrufs 
    131131         */ 
    132         public abstract Response getResponse(); 
     132        public Response getResponse(); 
    133133         
    134134        /** 
     
    136136         * @param response Das Response-Objekt 
    137137         */ 
    138         public abstract void setResponse(Response response); 
     138        public void setResponse(Response response); 
    139139         
    140140        /** 
    141          * Liefert eine pro Kontext einmalige Instanz einer Klasse. 
    142          * Sollte keine Instanz dieser Klasse im Kontext vorhanden sein, 
     141         * Liefert eine unter einem bestimmten Scope einmalige Instanz einer Klasse. 
     142         * Sollte keine Instanz dieser Klasse im Scope vorhanden sein, 
    143143         * wird dieses erstellt. 
    144          * Hinweis: Die Klasse muss die Annotation ContextInstance besitzen 
    145          * und auf den Wert SINGLETON gesetzt haben 
    146144         *  
    147          * @param <T> Eine Klasse, welche Kontextbezogen arbeiten kann 
     145         * @param <T> Eine Klasse 
    148146         * @param cls Die gewuenschte Klasse 
    149147         * @return Eine Instanz der Klase 
    150148         */ 
    151         public abstract <T> T get(Class<T> cls); 
     149        public <T> T get(Class<T> cls); 
     150         
     151        /** 
     152         * Entfernt die unter einem bestimmten Scope gueltige Instanz dieser Klasse 
     153         * @param cls Die Klasse 
     154         */ 
     155        public void remove(Class<?> cls); 
    152156         
    153157        /** 
     
    158162         * @return Die Session-ID oder ein leerer String 
    159163         */ 
    160         public abstract String getSession(); 
     164        public String getSession(); 
    161165         
    162166        /** 
     
    166170         * @param value Der neue Wert der Variablen 
    167171         */ 
    168         public abstract void putVariable(Class<?> cls, String varname, Object value); 
     172        public void putVariable(Class<?> cls, String varname, Object value); 
    169173         
    170174        /** 
     
    174178         * @return Die Variable oder <code>null</code>, falls die Variable nicht existiert 
    175179         */ 
    176         public abstract Object getVariable(Class<?> cls, String varname); 
     180        public Object getVariable(Class<?> cls, String varname); 
    177181         
    178182        /** 
     
    181185         * 
    182186         */ 
    183         public abstract void revalidate(); 
     187        public void revalidate(); 
    184188         
    185189        /** 
     
    188192         * @param listener Der Listener 
    189193         */ 
    190         public abstract void registerListener(ContextListener listener); 
     194        public void registerListener(ContextListener listener); 
    191195} 
  • src/net/driftingsouls/ds2/server/framework/ContextInstance.java

    rae09dfe rc09e0ad  
    3535public @interface ContextInstance { 
    3636        /** 
    37          * Der Typ der kontextgebundenen Klasse 
     37         * Der Scope der kontextgebundenen Klasse 
    3838         * @author Christopher Jung 
    3939         * 
    4040         */ 
    41         enum Type { 
     41        enum Scope { 
    4242                /** 
    43                  * Die Klasse darf lediglich einmal pro Kontext vorkommen 
     43                 * Die Klasse darf lediglich pro Request einmal vorkommen. 
     44                 * Verschiedene Requests muessen unterschiedliche Instanzen haben 
    4445                 */ 
    45                 SINGLETON 
     46                REQUEST, 
     47                /** 
     48                 * Die Klasse darf lediglich einmal pro Session vorkommen. 
     49                 * Verschiedene Sessions muessen unterschiedliche Instanzen haben 
     50                 */ 
     51                SESSION 
    4652        }; 
    4753         
    4854        /** 
    49          * Gibt den Typ der kontextgebundenen Klasse zurueck 
    50          * @return der Typ 
     55         * Gibt den Scope der kontextgebundenen Klasse zurueck 
     56         * @return der Scope 
    5157         */ 
    52         Type value(); 
     58        Scope value(); 
    5359} 
  • src/net/driftingsouls/ds2/server/framework/authentication/AuthenticationManager.java

    r5dc487d rc09e0ad  
    2020 
    2121import net.driftingsouls.ds2.server.framework.BasicUser; 
    22 import net.driftingsouls.ds2.server.framework.Session; 
    2322 
    2423/** 
     
    3433         * @param password Das Passwort im Klartext 
    3534         * @param useGfxPak <code>true</code>, falls ein evt angegebenes Grafikpak genutzt werden soll 
    36          * @return Session Die neu erstellte Session 
     35         * @return Der Account des eingeloggten Benutzers 
    3736         * @throws AuthenticationException Falls der Loginvorgang nicht erfolgreich ist 
    3837         */ 
    39         public Session login(String username, String password, boolean useGfxPak) 
     38        public BasicUser login(String username, String password, boolean useGfxPak) 
    4039                        throws AuthenticationException; 
    4140 
     
    5049         * @param user Der Account, in den der Admin eingeloggt werden soll 
    5150         * @param attach <code>true</code>, falls die Adminrechte an die neue Session "angeklebt" werden sollen 
    52          * @return Die neu erstellte Session 
     51         * @return Der Account des eingeloggten Benutzers 
    5352         * @throws AuthenticationException Falls der Loginvorgang nicht moeglich ist 
    5453         */ 
    55         public Session adminLogin(BasicUser user, boolean attach) throws AuthenticationException; 
     54        public BasicUser adminLogin(BasicUser user, boolean attach) throws AuthenticationException; 
    5655 
    5756        /** 
  • src/net/driftingsouls/ds2/server/framework/authentication/DefaultAuthenticationManager.java

    r5dc487d rc09e0ad  
    2626import net.driftingsouls.ds2.server.framework.Context; 
    2727import net.driftingsouls.ds2.server.framework.ContextMap; 
    28 import net.driftingsouls.ds2.server.framework.Session; 
    2928import net.driftingsouls.ds2.server.framework.db.Database; 
    3029import net.driftingsouls.ds2.server.framework.pipeline.Request; 
    3130 
    32 import org.apache.commons.lang.math.RandomUtils; 
    3331import org.apache.commons.logging.Log; 
    3432import org.apache.commons.logging.LogFactory; 
     
    4139public class DefaultAuthenticationManager implements AuthenticationManager { 
    4240        private static final Log log = LogFactory.getLog(DefaultAuthenticationManager.class); 
    43         private static final ServiceLoader<LoginEventListener> listenerList = ServiceLoader.load(LoginEventListener.class); 
     41        private static final ServiceLoader<LoginEventListener> loginListenerList = ServiceLoader.load(LoginEventListener.class); 
     42        private static final ServiceLoader<AuthenticateEventListener> authListenerList = ServiceLoader.load(AuthenticateEventListener.class); 
    4443         
    45         private static final String[] actionBlockingPhrases = { 
    46                 "Immer mit der Ruhe!\nDer arme Server ist schon total erschl&ouml;pft.\nG&ouml;nn ihm mal ein oder zwei Minuten Pause :)", 
    47                 "Laaaaangsaaaaam!\nDeine Maus hat ja schon nen Krampf von dem vielen geklicke bekommen!\nMach mal eine kleine Pause und g&ouml;nn ihr die Entspannung...", 
    48                 "In der Ruhe liegt die Kraft!\nNur der arme Server hat wegen deiner Klickerei keine Ruhe und somit auch keine Kraft mehr. Lass ihm eine kleine Verschnaufpause und mach dann weiter.", 
    49                 "Vorsicht mein junger Padawan!\nBei diesem Klicktempo k&ouml;nntest du aus versehen auf den Selbstzerst&ouml;rungsknopf dr&uuml;cken! Mach eine kurze Pause und klicke dann langsam und gewissenhaft weiter..." 
    50         }; 
    51          
    52         public Session login(String username, String password, boolean useGfxPak) throws AuthenticationException { 
     44        public BasicUser login(String username, String password, boolean useGfxPak) throws AuthenticationException { 
    5345                Context context = ContextMap.getContext(); 
    5446                org.hibernate.Session db = context.getDB(); 
     
    8577                } 
    8678                 
    87                 for( LoginEventListener listener : listenerList ) { 
     79                for( LoginEventListener listener : loginListenerList ) { 
    8880                        listener.onLogin(user); 
    8981                } 
    90                  
    91                 checkTickInProgress(context, user); 
    9282 
     83                log.info("Login "+user.getId()); 
    9384                Common.writeLog("login.log",Common.date( "j.m.Y H:i:s")+": <"+request.getRemoteAddress()+"> ("+user.getId()+") <"+user.getUN()+"> Login von Browser <"+request.getUserAgent()+">\n"); 
    9485 
    95                 return createNewSession(context, user, useGfxPak); 
    96         } 
    97  
    98         private void checkTickInProgress(Context context, BasicUser user) throws TickInProgressException { 
    99                 org.hibernate.Session db = context.getDB(); 
     86                JavaSession jsession = context.get(JavaSession.class); 
     87                jsession.setUser(user); 
     88                jsession.setUseGfxPak(useGfxPak); 
     89                jsession.setIP("<"+context.getRequest().getRemoteAddress()+">"); 
    10090                 
    101                 Session session = (Session)db.createQuery("from Session where user=? and tick!=0") 
    102                         .setEntity(0, user) 
    103                         .uniqueResult(); 
    104  
    105                 if( session != null ) { 
    106                         throw new TickInProgressException(); 
    107                 } 
    108         } 
    109  
    110         private Session createNewSession(Context context, BasicUser user, boolean useGfxPak) { 
    111                 org.hibernate.Session db = context.getDB(); 
    112                  
    113                 db.createQuery("delete from Session where user=? and attach is null") 
    114                         .setEntity(0, user) 
    115                         .executeUpdate(); 
    116                  
    117                 Session session = new Session(user); 
    118                 session.setIP("<"+context.getRequest().getRemoteAddress()+">"); 
    119                 session.setUseGfxPak(useGfxPak); 
    120                 db.persist(session); 
    121                  
    122                 context.commit(); 
    123                 return session; 
     91                return user; 
    12492        } 
    12593 
     
    135103        public void logout() { 
    136104                Context context = ContextMap.getContext(); 
    137                  
    138                 context.getDB().createQuery("delete from Session where session= :sess or attach= :sess") 
    139                         .setString("sess", context.getSession()) 
    140                         .executeUpdate(); 
     105                context.remove(JavaSession.class); 
    141106        } 
    142107 
    143         public Session adminLogin(BasicUser user, boolean attach) throws AuthenticationException { 
     108        public BasicUser adminLogin(BasicUser user, boolean attach) throws AuthenticationException { 
    144109                Context context = ContextMap.getContext(); 
    145110                 
    146                 Session session = new Session(user); 
    147                 session.setIP("<"+context.getRequest().getRemoteAddress()+">"); 
    148                 session.setUseGfxPak(false); 
     111                BasicUser oldUser = context.getActiveUser(); 
     112 
     113                JavaSession jsession = context.get(JavaSession.class); 
     114                jsession.setUser(user); 
     115                jsession.setIP("<"+context.getRequest().getRemoteAddress()+">"); 
     116                jsession.setUseGfxPak(false); 
    149117                if( attach ) { 
    150                         session.setAttach(context.getSession()); 
     118                        jsession.setAttach(oldUser); 
    151119                } 
    152                 context.getDB().save(session); 
    153120                 
    154                 return session
     121                return user
    155122        } 
    156123         
    157124        public void authenticateCurrentSession() { 
    158125                Context context = ContextMap.getContext(); 
     126 
     127                String errorurl = Configuration.getSetting("URL")+"ds?module=portal&action=login"; 
    159128                 
    160                 Request request = context.getRequest(); 
    161                 org.hibernate.Session db = context.getDB(); 
     129                JavaSession jsession = context.get(JavaSession.class); 
    162130                 
    163                 String sess = request.getParameter("sess"); 
    164                  
    165                 String errorurl = Configuration.getSetting("URL")+"ds?module=portal&action=login"; 
    166          
    167                 if( (sess == null) || sess.equals("") ) { 
    168                         return; 
    169                 } 
    170                  
    171                 long time = Common.time(); 
    172                 Session sessdata = (Session)db.get(Session.class, sess); 
    173                  
    174                 if( sessdata == null ) { 
    175                         context.addError( "Sie sind offenbar nicht eingeloggt", errorurl ); 
    176  
     131                if( jsession == null || jsession.getUser() == null ) { 
    177132                        return; 
    178133                } 
    179134 
    180                 if( sessdata.getTick() ) { 
    181                         context.addError( "Im Moment werden einige Tick-Berechnungen f&uuml;r sie durchgef&uuml;hrt. Bitte haben sie daher ein wenig Geduld",  
    182                                         request.getRequestURL() +  
    183                                                 (request.getQueryString() != null ? "?" + request.getQueryString() : "")  
    184                         ); 
    185  
    186                         return; 
    187                 } 
    188          
    189                 BasicUser user = sessdata.getUser(); 
    190                 user.setSessionData(sessdata); 
    191                 if( !user.hasFlag(BasicUser.FLAG_DISABLE_IP_SESSIONS) && !sessdata.isValidIP(request.getRemoteAddress()) ) { 
     135                BasicUser user = jsession.getUser(); 
     136                user.setSessionData(jsession.getUseGfxPak()); 
     137                if( !user.hasFlag(BasicUser.FLAG_DISABLE_IP_SESSIONS) && !jsession.isValidIP(context.getRequest().getRemoteAddress()) ) { 
    192138                        context.addError( "Diese Session ist einer anderen IP zugeordnet", errorurl ); 
    193139 
    194140                        return; 
    195141                } 
    196          
    197                 if( !user.hasFlag(BasicUser.FLAG_DISABLE_AUTO_LOGOUT) && (Common.time() - sessdata.getLastAction() > Configuration.getIntSetting("AUTOLOGOUT_TIME")) ) { 
    198                         db.delete(sessdata); 
    199                         context.addError( "Diese Session ist bereits abgelaufen", errorurl ); 
    200  
     142                 
     143                try { 
     144                        for( AuthenticateEventListener listener : authListenerList ) { 
     145                                listener.onAuthenticate(user); 
     146                        } 
     147                } 
     148                catch( AuthenticationException e ) { 
    201149                        return; 
    202                 } 
    203                  
    204                 final long oldtime = sessdata.getLastAction(); 
    205                  
    206                 sessdata.setLastAction(time); 
    207                 context.commit(); 
    208                  
    209                 if( !user.hasFlag(BasicUser.FLAG_NO_ACTION_BLOCKING) ) { 
    210                         // Alle 1.5 Sekunden Counter um 1 reduzieren, sofern mindestens 5 Sekunden Pause vorhanden waren 
    211                         int reduce = (int)((time - oldtime)/1.5); 
    212                         if( time < oldtime + 5 ) { 
    213                                 reduce = -1; 
    214                         } 
    215                         int actioncounter = sessdata.getActionCounter()-reduce; 
    216                         if( actioncounter < 0 ) { 
    217                                 actioncounter = 0; 
    218                         } 
    219  
    220                         if( reduce > 0 ) { 
    221                                 final int value = sessdata.getActionCounter() - reduce; 
    222                                  
    223                                 sessdata.setActionCounter(value > 0 ? value : 0); 
    224                         } 
    225                         else if( reduce < 0 ) { 
    226                                 sessdata.setActionCounter(sessdata.getActionCounter()+1); 
    227                         } 
    228                          
    229                         int sleep = -1; 
    230                          
    231                         // Bei viel zu hoher Aktivitaet einfach die Ausfuehrung mit einem Fehler beenden 
    232                         if( actioncounter >= 35 ) { 
    233                                 context.addError( actionBlockingPhrases[RandomUtils.nextInt(actionBlockingPhrases.length)], 
    234                                                 request.getRequestURL() +  
    235                                                 (request.getQueryString() != null ? "?" + request.getQueryString() : "") ); 
    236                                  
    237                                 return; 
    238                         } 
    239                         // Bei hoher Aktivitaet stattdessen nur eine Pause einlegen 
    240                         else if( actioncounter > 10 ) { 
    241                                 sleep = 100 * actioncounter; 
    242                         } 
    243                          
    244                         if( sleep > 0 ) { 
    245                                 try { 
    246                                         Thread.sleep(2500); 
    247                                 } 
    248                                 catch( InterruptedException e ) { 
    249                                         log.error(e,e); 
    250                                 } 
    251                         } 
    252150                } 
    253151 
     
    255153                user.setInactivity(0); 
    256154                 
    257                 if( (sessdata.getAttach() != null) && !sessdata.getAttach().equals("-1") ) { 
    258                         Session attachSession = (Session)db.get(Session.class, sessdata.getAttach()); 
    259                         if( attachSession != null) { 
    260                                 user.attachToUser(attachSession.getUser());      
    261                         } 
     155                if( jsession.getAttach() != null ) { 
     156                        user.attachToUser(jsession.getAttach()); 
    262157                } 
    263158                 
  • src/net/driftingsouls/ds2/server/framework/pipeline/HttpRequest.java

    r9fc4d87 rc09e0ad  
    2222import java.io.InputStream; 
    2323import java.io.UnsupportedEncodingException; 
     24import java.lang.reflect.Constructor; 
     25import java.lang.reflect.InvocationTargetException; 
    2426import java.util.ArrayList; 
    2527import java.util.HashMap; 
     
    2830 
    2931import javax.servlet.http.HttpServletRequest; 
     32import javax.servlet.http.HttpSession; 
    3033 
    3134import net.driftingsouls.ds2.server.framework.Loggable; 
     
    184187                return result; 
    185188        } 
     189         
     190        @SuppressWarnings("unchecked") 
     191        public <T> T getFromSession(Class<T> cls) { 
     192                HttpSession session = this.request.getSession(false); 
     193                 
     194                if( session == null ) { 
     195                        return null; 
     196                } 
     197                Object obj = session.getAttribute(getClass().getName()+"#"+cls.getName()); 
     198                if( obj == null ) { 
     199                        try { 
     200                                Constructor constr = cls.getConstructor(); 
     201                                constr.setAccessible(true); 
     202                                obj = constr.newInstance(); 
     203                        } 
     204                        catch( InstantiationException e ) { 
     205                                LOG.error("getFromSession for "+cls.getName()+" failed", e); 
     206                                return null; 
     207                        } 
     208                        catch( IllegalAccessException e ) { 
     209                                LOG.error("getFromSession for "+cls.getName()+" failed", e); 
     210                                return null; 
     211                        } 
     212                        catch( InvocationTargetException e ) { 
     213                                LOG.error("getFromSession for "+cls.getName()+" failed", e); 
     214                                return null; 
     215                        } 
     216                        catch( NoSuchMethodException e ) { 
     217                                LOG.error("getFromSession for "+cls.getName()+" failed", e); 
     218                                return null; 
     219                        } 
     220                        session.setAttribute(getClass().getName()+"#"+cls.getName(), obj); 
     221                } 
     222                if( cls.isInstance(obj) ) { 
     223                        return (T)obj; 
     224                } 
     225                LOG.error("getFromSession for "+cls.getName()+" failed - invalid type"); 
     226                 
     227                return null; 
     228        } 
     229         
     230        public void removeFromSession(Class<?> cls) { 
     231                HttpSession session = this.request.getSession(false); 
     232                 
     233                if( session == null ) { 
     234                        return; 
     235                }&