Changeset 28b2039b931422fb3ad1ca7d82bea700721e6142

Show
Ignore:
Timestamp:
12/08/07 14:37:49 (1 year ago)
Author:
Christopher Jung <bktheg@web.de>
git-committer:
Christopher Jung <bktheg@web.de> 1197121069 +0100
git-parent:

[2d1909f5e2b47ba4dcaeb4fd0fb06671d95c8e0b]

git-author:
Christopher Jung <bktheg@web.de> 1197121069 +0100
Message:

Umstellung ScriptParser? auf javax.script.* Teil 2

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/net/driftingsouls/ds2/server/AdminCommands.java

    r2d1909f r28b2039  
    3333 
    3434import javax.imageio.ImageIO; 
     35import javax.script.Bindings; 
     36import javax.script.ScriptContext; 
     37import javax.script.ScriptEngine; 
     38import javax.script.ScriptException; 
    3539 
    3640import net.driftingsouls.ds2.server.bases.Base; 
     
    5054import net.driftingsouls.ds2.server.framework.Loggable; 
    5155import net.driftingsouls.ds2.server.framework.caches.CacheManager; 
    52 import net.driftingsouls.ds2.server.framework.db.Database; 
    53 import net.driftingsouls.ds2.server.framework.db.SQLQuery; 
    54 import net.driftingsouls.ds2.server.framework.db.SQLResultRow; 
    5556import net.driftingsouls.ds2.server.scripting.ScriptParser; 
     57import net.driftingsouls.ds2.server.scripting.entities.RunningQuest; 
    5658import net.driftingsouls.ds2.server.ships.Ship; 
    5759import net.driftingsouls.ds2.server.ships.ShipTypeData; 
     
    319321        private static String cmdQuest(Context context, String[] command) { 
    320322                String output = ""; 
    321                 Database db = context.getDatabase(); 
     323                org.hibernate.Session db = context.getDB(); 
    322324                 
    323325                String cmd = command[1]; 
     
    325327                        int rqid = Integer.parseInt(command[2]); 
    326328                         
    327                         ScriptParser scriptparser = context.get(ContextCommon.class).getScriptParser(ScriptParser.NameSpace.QUEST); 
    328                         scriptparser.setLogFunction(ScriptParser.LOGGER_NULL); 
    329                          
    330                         SQLResultRow runningquest = db.first("SELECT * FROM quests_running WHERE id="+rqid); 
    331                          
    332                         if( runningquest.getString("uninstall").length() > 0 ) { 
    333                                 scriptparser.setRegister("USER", runningquest.getInt("user")); 
    334                                 scriptparser.setRegister("QUEST", "r"+rqid); 
    335                                  
    336                                 scriptparser.eval( runningquest.getString("uninstall"), "0" ); 
    337                         }        
    338                          
    339                         db.update("DELETE FROM quests_running WHERE id="+rqid); 
     329                        ScriptEngine scriptparser = context.get(ContextCommon.class).getScriptParser("DSQuestScript"); 
     330                        final Bindings engineBindings = scriptparser.getContext().getBindings(ScriptContext.ENGINE_SCOPE); 
     331                         
     332                        scriptparser.getContext().setErrorWriter(ScriptParser.LOGGER_NULL); 
     333                         
     334                        RunningQuest runningquest = (RunningQuest)db.get(RunningQuest.class, rqid); 
     335                         
     336                        if( !runningquest.getUninstall().isEmpty() ) { 
     337                                engineBindings.put("USER", runningquest.getUser().getID()); 
     338                                engineBindings.put("QUEST", "r"+rqid); 
     339                                engineBindings.put("_PARAMETERS", "0"); 
     340                                 
     341                                try { 
     342                                        scriptparser.eval( runningquest.getUninstall() ); 
     343                                } 
     344                                catch( ScriptException e ) { 
     345                                        throw new RuntimeException(e); 
     346                                } 
     347                        } 
     348                         
     349                        db.delete(runningquest); 
    340350                } 
    341351                else if( cmd.equals("list") ) { 
    342352                        output = "Laufende Quests:\n"; 
    343                         SQLQuery rquest = db.query("SELECT qr.id,qr.questid,qr.userid,q.name " + 
    344                                        "FROM quests_running qr JOIN quests q ON qr.questid=q.id"); 
    345                         while( rquest.next() ) { 
    346                                 output += "* "+rquest.getInt("id")+" - "+rquest.getString("name")+" ("+rquest.getInt("questid")+") - userid "+rquest.getInt("userid")+"\n"; 
    347                         } 
    348                         rquest.free(); 
     353                        List rquestList = db.createQuery("from RunningQuest rq inner join fetch rq.quest").list(); 
     354                        for( Iterator iter=rquestList.iterator(); iter.hasNext(); ) { 
     355                               RunningQuest rquest = (RunningQuest)iter.next(); 
     356                                 
     357                               output += "* "+rquest.getId()+" - "+rquest.getQuest().getName()+" ("+rquest.getQuest().getId()+") - userid "+rquest.getUser().getID()+"\n"; 
     358                        } 
    349359                } 
    350360                else { 
  • src/net/driftingsouls/ds2/server/ContextCommon.java

    r2a7339d r28b2039  
    2222import java.util.Map; 
    2323 
     24import javax.script.ScriptEngine; 
     25import javax.script.ScriptEngineManager; 
     26 
    2427import net.driftingsouls.ds2.server.framework.Context; 
    2528import net.driftingsouls.ds2.server.framework.ContextInstance; 
    26 import net.driftingsouls.ds2.server.scripting.ScriptParser; 
    2729import net.driftingsouls.ds2.server.scripting.ScriptParserContext; 
    2830 
     
    5759        } 
    5860         
    59         private Map<ScriptParser.NameSpace,ScriptParser> scriptParsers = new HashMap<ScriptParser.NameSpace,ScriptParser>(); 
     61        private Map<String,ScriptEngine> scriptParsers = new HashMap<String,ScriptEngine>(); 
    6062         
    6163        /** 
    62          * Gibt eine Instanz des ScriptParsers fuer den angegebenen Namespace zurueck 
    63          * @param namespace Der Namespace des ScriptParsers 
    64          * @return der ScriptParser 
     64         * Gibt eine Instanz einer ScriptEngine zurueck 
     65         * @param name Der Name der ScriptEngine 
     66         * @return die ScriptEngine 
    6567         */ 
    66         public ScriptParser getScriptParser( ScriptParser.NameSpace namespace ) { 
    67                 if( !scriptParsers.containsKey(namespace) ) { 
    68                         ScriptParser parser = new ScriptParser(namespace); 
     68        public ScriptEngine getScriptParser( String name ) { 
     69                if( !scriptParsers.containsKey(name) ) { 
     70                        ScriptEngine parser = new ScriptEngineManager().getEngineByName(name); 
    6971                        parser.setContext(new ScriptParserContext()); 
    70                         scriptParsers.put(namespace, parser); 
     72                        scriptParsers.put(name, parser); 
    7173                        return parser; 
    7274                } 
    73                 return scriptParsers.get(namespace); 
     75                return scriptParsers.get(name); 
    7476        } 
    7577} 
  • src/net/driftingsouls/ds2/server/battles/Battle.java

    r957f039 r28b2039  
    4040import javax.persistence.Table; 
    4141import javax.persistence.Transient; 
     42import javax.script.ScriptEngine; 
    4243 
    4344import net.driftingsouls.ds2.server.ContextCommon; 
     
    18161817                        String onendhandler = this.onend; 
    18171818                        if( (onendhandler != null) && (onendhandler.length() > 0) ) {                    
    1818                                 ScriptParser scriptparser = context.get(ContextCommon.class).getScriptParser(ScriptParser.NameSpace.QUEST); 
     1819                                ScriptEngine scriptparser = context.get(ContextCommon.class).getScriptParser("DSQuestScript"); 
    18191820                                if( context.getActiveUser() != null ) { 
    18201821                                        BasicUser activeuser = context.getActiveUser(); 
    18211822                                        if( !activeuser.hasFlag(User.FLAG_SCRIPT_DEBUGGING) ) { 
    1822                                                 scriptparser.setLogFunction(ScriptParser.LOGGER_NULL); 
     1823                                                scriptparser.getContext().setErrorWriter(ScriptParser.LOGGER_NULL); 
    18231824                                        } 
    18241825                                } 
    18251826                                else { 
    1826                                         scriptparser.setLogFunction(ScriptParser.LOGGER_NULL); 
    1827                                 } 
    1828                                  
    1829                                 Quests.executeEvent( scriptparser, onendhandler, (context.getActiveUser() != null ? context.getActiveUser().getID() : 0), "" ); 
     1827                                        scriptparser.getContext().setErrorWriter(ScriptParser.LOGGER_NULL); 
     1828                                } 
     1829                                 
     1830                                User questUser = (User)context.getActiveUser(); 
     1831                                if( questUser == null ) { 
     1832                                        questUser = (User)db.get(User.class, 0); 
     1833                                } 
     1834                                Quests.executeEvent( scriptparser, onendhandler, questUser, "", false ); 
    18301835                        } 
    18311836                } 
  • src/net/driftingsouls/ds2/server/modules/SchiffController.java

    r2d1909f r28b2039  
    2828import java.util.List; 
    2929import java.util.Map; 
     30 
     31import javax.script.Bindings; 
     32import javax.script.ScriptContext; 
     33import javax.script.ScriptEngine; 
     34import javax.script.ScriptException; 
    3035 
    3136import net.driftingsouls.ds2.server.ContextCommon; 
     
    153158                 
    154159                if( !action.equals("communicate") && !action.equals("onmove") && !action.equals("onenter") && (ship.getLock() != null) && !ship.getLock().equals("") ) { 
    155                         ScriptParser scriptparser = getContext().get(ContextCommon.class).getScriptParser( ScriptParser.NameSpace.QUEST ); 
    156                         scriptparser.setShip(ship); 
     160                        ScriptEngine scriptparser = getContext().get(ContextCommon.class).getScriptParser("DSQuestScript"); 
     161                        scriptparser.getContext().setAttribute("_SHIP", ship, ScriptContext.ENGINE_SCOPE); 
     162                         
    157163                        if( !user.hasFlag( User.FLAG_SCRIPT_DEBUGGING ) ) { 
    158                                 scriptparser.setLogFunction(ScriptParser.LOGGER_NULL); 
     164                                scriptparser.getContext().setErrorWriter(ScriptParser.LOGGER_NULL); 
    159165                        } 
    160166                         
     
    747753                } 
    748754         
    749                 ScriptParser scriptparser = getContext().get(ContextCommon.class).getScriptParser( ScriptParser.NameSpace.QUEST ); 
    750                 scriptparser.setShip(ship); 
     755                ScriptEngine scriptparser = getContext().get(ContextCommon.class).getScriptParser("DSQuestScript"); 
     756                final Bindings engineBindings = scriptparser.getContext().getBindings(ScriptContext.ENGINE_SCOPE); 
     757                 
     758                engineBindings.put("_SHIP", ship); 
    751759                if( !user.hasFlag( User.FLAG_SCRIPT_DEBUGGING ) ) { 
    752                         scriptparser.setLogFunction(ScriptParser.LOGGER_NULL); 
     760                        scriptparser.getContext().setErrorWriter(ScriptParser.LOGGER_NULL); 
    753761                } 
    754762                 
    755763                Quests.currentEventURL.set("&action=communicate&communicate="+communicate); 
    756          
    757                 if( (lock != null) && (lock.length > 2) ) {              
    758                         scriptparser.setRegister("LOCKEXEC", "1"); 
    759                 } 
    760                  
    761                 scriptparser.setRegister("TARGETSHIP", Integer.toString(communicate)); 
     764 
     765                engineBindings.put("TARGETSHIP", Integer.toString(communicate)); 
    762766         
    763767                parameterString("execparameter"); 
     
    773777                        return; 
    774778                } 
    775                 Quests.executeEvent( scriptparser, targetship.getOnCommunicate(), user.getID(), execparameter ); 
     779                Quests.executeEvent( scriptparser, targetship.getOnCommunicate(), user, execparameter, lock != null && lock.length > 2 ); 
    776780                 
    777781                redirect(); 
     
    796800                } 
    797801         
    798                 ScriptParser scriptparser = getContext().get(ContextCommon.class).getScriptParser( ScriptParser.NameSpace.QUEST ); 
    799                 scriptparser.setShip(ship); 
     802                ScriptEngine scriptparser = getContext().get(ContextCommon.class).getScriptParser("DSQuestScript"); 
     803                scriptparser.getContext().setAttribute("_SHIP", ship, ScriptContext.ENGINE_SCOPE); 
     804                 
    800805                if( !user.hasFlag( User.FLAG_SCRIPT_DEBUGGING ) ) { 
    801                         scriptparser.setLogFunction(ScriptParser.LOGGER_NULL); 
     806                        scriptparser.getContext().setErrorWriter(ScriptParser.LOGGER_NULL); 
    802807                } 
    803808         
    804809                Quests.currentEventURL.set("&action=onmove"); 
    805          
    806                 if( lock.length > 2 ) {          
    807                         scriptparser.setRegister("LOCKEXEC", "1"); 
    808                 } 
    809          
     810 
    810811                parameterString("execparameter"); 
    811812                String execparameter = getString( "execparameter" ); 
     
    820821                } 
    821822 
    822                 Quests.executeEvent( scriptparser, ship.getOnMove(), user.getID(), execparameter ); 
     823                Quests.executeEvent( scriptparser, ship.getOnMove(), user, execparameter, lock.length > 2 ); 
    823824         
    824825                redirect(); 
     
    844845                } 
    845846         
    846                 ScriptParser scriptparser = getContext().get(ContextCommon.class).getScriptParser( ScriptParser.NameSpace.QUEST ); 
    847                 scriptparser.setShip(ship); 
     847                ScriptEngine scriptparser = getContext().get(ContextCommon.class).getScriptParser("DSQuestScript"); 
     848                scriptparser.getContext().setAttribute("_SHIP", ship, ScriptContext.ENGINE_SCOPE); 
     849                 
    848850                if( !user.hasFlag( User.FLAG_SCRIPT_DEBUGGING ) ) { 
    849                         scriptparser.setLogFunction(ScriptParser.LOGGER_NULL); 
    850                 } 
    851                  
    852                 // TODO: migrate to libquests 
     851                        scriptparser.getContext().setErrorWriter(ScriptParser.LOGGER_NULL); 
     852                } 
     853                 
     854                // TODO: migrate to Quests.executeEvent 
    853855                 
    854856                if( lock.length < 3 ) { 
     
    896898                } 
    897899 
     900                final Bindings engineBindings = scriptparser.getContext().getBindings(ScriptContext.ENGINE_SCOPE); 
     901                 
    898902                Script script = (Script)db.get(Script.class, Integer.valueOf(usescript)); 
    899                 scriptparser.setRegister("USER", Integer.toString(user.getID())); 
     903                engineBindings.put("USER", Integer.toString(user.getID())); 
    900904                if( !usequest.equals("") ) { 
    901                         scriptparser.setRegister("QUEST", "r"+runningdata.getId()); 
    902                 } 
    903                 scriptparser.setRegister("SCRIPT", usescript); 
    904                 scriptparser.setRegister("SECTOR", ship.getLocation().toString()); 
     905                        engineBindings.put("QUEST", "r"+runningdata.getId()); 
     906                } 
     907                engineBindings.put("SCRIPT", usescript); 
     908                engineBindings.put("SECTOR", ship.getLocation().toString()); 
    905909                if( (lock.length > 2) ) {                
    906                         scriptparser.setRegister("LOCKEXEC", "1"); 
    907                 } 
    908  
    909                 scriptparser.eval(script.getScript(), execparameter); 
    910          
    911                 usequest = scriptparser.getRegister("QUEST"); 
     910                        engineBindings.put("LOCKEXEC", "1"); 
     911                } 
     912 
     913                engineBindings.put("_PARAMETERS", execparameter); 
     914                try { 
     915                        scriptparser.eval(script.getScript()); 
     916                } 
     917                catch( ScriptException e ) { 
     918                        throw new RuntimeException(e); 
     919                } 
     920         
     921                usequest = (String)engineBindings.get("QUEST"); 
    912922                 
    913923                if( !usequest.equals("") ) { 
     
    11791189                db.refresh(ship); 
    11801190                         
    1181                 ScriptParser scriptparser = getContext().get(ContextCommon.class).getScriptParser( ScriptParser.NameSpace.QUEST ); 
     1191                ScriptEngine scriptparser = getContext().get(ContextCommon.class).getScriptParser("DSQuestScript"); 
    11821192                if( ship == null ) { 
    1183                         if( (scriptparser != null) && (scriptparser.getContext().getOutput().length() != 0) ) { 
     1193                        if( (scriptparser != null) && (scriptparser.getContext().getWriter().toString().length() != 0) ) { 
    11841194                                t.setVar("ship.scriptparseroutput", 
    1185                                                 scriptparser.getContext().getOutput().replace("{{var.sessid}}", getString("sess")) ); 
     1195                                                scriptparser.getContext().getWriter().toString().replace("{{var.sessid}}", getString("sess")) ); 
    11861196                        } 
    11871197                        else { 
     
    11941204                 
    11951205                if( ship.getBattle() != null ) { 
    1196                         if( (scriptparser != null) && (scriptparser.getContext().getOutput().length() > 0) ) { 
     1206                        if( (scriptparser != null) && (scriptparser.getContext().getWriter().toString().length() > 0) ) { 
    11971207                                t.setVar("ship.scriptparseroutput", 
    1198                                                 scriptparser.getContext().getOutput().replace("{{var.sessid}}", getString("sess")) ); 
     1208                                                scriptparser.getContext().getWriter().toString().replace("{{var.sessid}}", getString("sess")) ); 
    11991209                        } 
    12001210                 
     
    15621572                */ 
    15631573         
    1564                 if( (scriptparser != null) && (scriptparser.getContext().getOutput().length() > 0) ) { 
     1574                if( (scriptparser != null) ) { 
    15651575                        t.setVar("ship.scriptparseroutput", 
    1566                                         scriptparser.getContext().getOutput().replace("{{var.sessid}}", getString("sess"))); 
     1576                                        scriptparser.getContext().getWriter().toString().replace("{{var.sessid}}", getString("sess"))); 
    15671577                } 
    15681578         
  • src/net/driftingsouls/ds2/server/modules/UeberController.java

    r2d1909f r28b2039  
    2525import java.util.Iterator; 
    2626import java.util.List; 
     27 
     28import javax.script.Bindings; 
     29import javax.script.ScriptContext; 
     30import javax.script.ScriptEngine; 
     31import javax.script.ScriptEngineManager; 
     32import javax.script.ScriptException; 
    2733 
    2834import net.driftingsouls.ds2.server.ContextCommon; 
     
    164170                } 
    165171                 
    166                 ScriptParser scriptparser = new ScriptParser( ScriptParser.NameSpace.QUEST ); 
     172                ScriptEngine scriptparser = new ScriptEngineManager().getEngineByName("DSQuestScript"); 
    167173                if( !getUser().hasFlag( User.FLAG_SCRIPT_DEBUGGING ) ) { 
    168                         scriptparser.setLogFunction(ScriptParser.LOGGER_NULL); 
     174                        scriptparser.getContext().setErrorWriter(ScriptParser.LOGGER_NULL); 
    169175                } 
    170176 
     
    180186                        return; 
    181187                } 
    182                 scriptparser.setRegister("USER", Integer.toString(getUser().getID())); 
    183                 scriptparser.setRegister("QUEST", "r"+questid); 
    184                 scriptparser.eval(":0\n!ENDQUEST\n!QUIT","0"); 
     188                final Bindings engineBindings = scriptparser.getContext().getBindings(ScriptContext.ENGINE_SCOPE); 
     189                 
     190                engineBindings.put("USER", Integer.toString(getUser().getID())); 
     191                engineBindings.put("QUEST", "r"+questid); 
     192                engineBindings.put("_PARAMETERS", "0"); 
     193                try { 
     194                        scriptparser.eval(":0\n!ENDQUEST\n!QUIT"); 
     195                } 
     196                catch( ScriptException e ) { 
     197                        throw new RuntimeException(e); 
     198                } 
    185199                 
    186200                redirect();      
  • src/net/driftingsouls/ds2/server/modules/admin/PlayerDelete.java

    r2d1909f r28b2039  
    2424import java.util.List; 
    2525 
     26import javax.script.Bindings; 
     27import javax.script.ScriptContext; 
     28import javax.script.ScriptEngine; 
     29 
    2630import net.driftingsouls.ds2.server.ContextCommon; 
    2731import net.driftingsouls.ds2.server.bases.Base; 
     
    3640import net.driftingsouls.ds2.server.framework.Loggable; 
    3741import net.driftingsouls.ds2.server.framework.db.Database; 
    38 import net.driftingsouls.ds2.server.framework.db.SQLQuery; 
    3942import net.driftingsouls.ds2.server.modules.AdminController; 
    40 import net.driftingsouls.ds2.server.scripting.ScriptParser; 
    4143import net.driftingsouls.ds2.server.scripting.ScriptParserContext; 
     44import net.driftingsouls.ds2.server.scripting.entities.RunningQuest; 
    4245import net.driftingsouls.ds2.server.ships.Ship; 
    4346import net.driftingsouls.ds2.server.tasks.Taskmanager; 
     
    9396                } 
    9497 
    95                 ScriptParser scriptparser = context.get(ContextCommon.class).getScriptParser(ScriptParser.NameSpace.QUEST); 
     98                ScriptEngine scriptparser = context.get(ContextCommon.class).getScriptParser("DSQuestScript"); 
    9699                 
    97100                echo.append("Beende Quests....<br />\n"); 
    98                 SQLQuery rquest = database.query("SELECT * FROM quests_running WHERE userid=",userid); 
    99                 while( rquest.next() ) { 
    100                         scriptparser.cleanup(); 
     101                List rquestList = db.createQuery("from RunningQuest where user= :user") 
     102                        .setEntity("user", user) 
     103                        .list(); 
     104                for( Iterator iter=rquestList.iterator(); iter.hasNext(); ) { 
     105                        RunningQuest rquest = (RunningQuest)iter.next(); 
     106 
    101107                        try { 
    102108                                scriptparser.setContext( 
    103                                                 ScriptParserContext.fromStream(rquest.getBlob("execdata").getBinaryStream()) 
     109                                                ScriptParserContext.fromStream(rquest.getExecData().getBinaryStream()) 
    104110                                ); 
    105                                 scriptparser.setRegister("USER", userid); 
    106                                 scriptparser.setRegister("QUEST", "r"+rquest.getInt("id")); 
    107                                 scriptparser.eval(":0\n!ENDQUEST\n!QUIT","0"); 
     111                                final Bindings engineBindings = scriptparser.getContext().getBindings(ScriptContext.ENGINE_SCOPE); 
     112                                 
     113                                engineBindings.put("USER", userid); 
     114                                engineBindings.put("QUEST", "r"+rquest.getId()); 
     115                                engineBindings.put("_PARAMETERS", "0"); 
     116                                scriptparser.eval(":0\n!ENDQUEST\n!QUIT"); 
    108117                        } 
    109118                        catch( Exception e ) { 
    110                                 echo.append("Fehler beim Beenden des Quests "+rquest.getInt("questid")+": "+e); 
     119                                echo.append("Fehler beim Beenden des Quests "+rquest.getQuest().getId()+": "+e); 
    111120                                LOG.error(e,e); 
    112121                                echo.append(Common.tableEnd()); 
     
    115124                        } 
    116125                } 
    117                 rquest.free(); 
    118126                 
    119127                echo.append("Loesche 'Abgeschlossen'-Status bei Quests<br />\n"); 
    120                 database.update("DELETE FROM quests_completed WHERE userid="+userid); 
     128                db.createQuery("delete from CompletedQuest where user= :user") 
     129                        .setEntity("user", user) 
     130                        .executeUpdate(); 
    121131                 
    122132                if( user.getAlly() != null ) { 
     
    255265                 
    256266                echo.append("L&ouml;sche PM's...\n"); 
    257                 database.update("DELETE FROM transmissionen WHERE empfaenger="+userid); 
    258                 echo.append(database.affectedRows()+" gel&ouml;scht<br />\n"); 
    259                 database.update("UPDATE transmissionen SET sender=0 WHERE sender="+userid); 
     267                int affRows = db.createQuery("delete from PM where empfaenger = :user") 
     268                        .setEntity("user", user) 
     269                        .executeUpdate(); 
     270                echo.append(affRows+" gel&ouml;scht<br />\n"); 
     271                 
     272                db.createQuery("update PM set sender=0 where sender = :user") 
     273                        .setEntity("user", user) 
     274                        .executeUpdate(); 
    260275                 
    261276                echo.append("L&ouml;sche PM-Ordner...<br />\n"); 
     
    271286 
    272287                echo.append("L&ouml;sche Kontobewegungen...<br />\n"); 
    273                 database.update("DELETE FROM user_moneytransfer WHERE `from`=",userid," OR `to`=",userid); 
     288                db.createQuery("delete from UserMoneyTransfer where from= :user or to = :user") 
     289                        .setEntity("user", user) 
     290                        .executeUpdate(); 
    274291 
    275292                echo.append("L&ouml;sche Userlogo...<br />\n"); 
  • src/net/driftingsouls/ds2/server/modules/admin/QuestsQuick.java

    r2d1909f r28b2039  
    2323import java.util.Set; 
    2424 
     25import javax.script.Bindings; 
     26import javax.script.ScriptContext; 
     27import javax.script.ScriptEngine; 
     28import javax.script.ScriptException; 
     29 
    2530import net.driftingsouls.ds2.server.ContextCommon; 
    2631import net.driftingsouls.ds2.server.cargo.Cargo; 
     
    3641import net.driftingsouls.ds2.server.framework.db.SQLResultRow; 
    3742import net.driftingsouls.ds2.server.modules.AdminController; 
    38 import net.driftingsouls.ds2.server.scripting.ScriptParser; 
    3943import net.driftingsouls.ds2.server.scripting.ScriptParserContext; 
    4044 
     
    7983                        db.update("UPDATE quests_quick SET enabled=0 WHERE id="+id); 
    8084                         
    81                         ScriptParser scriptparser = context.get(ContextCommon.class).getScriptParser( ScriptParser.NameSpace.QUEST ); 
     85                        ScriptEngine scriptparser = context.get(ContextCommon.class).getScriptParser("DSQuestScript"); 
    8286                         
    8387                        SQLQuery rquest = db.query("SELECT * FROM quests_running WHERE id="+qquest.getInt("enabled")); 
    8488                        while( rquest.next() ) { 
    85                                 scriptparser.cleanup(); 
    8689                                try { 
    8790                                        Blob execdata = rquest.getBlob("execdata"); 
     
    9396                                        echo.append("WARNUNG: Konnte Questdaten nicht laden: Laufendes Quest "+rquest.getInt("id")+"<br />\n"); 
    9497                                } 
    95                                 scriptparser.setRegister("USER", rquest.getInt("userid")); 
    96                                 scriptparser.setRegister("QUEST", "r"+rquest.getInt("id")); 
    97                                 scriptparser.eval(":0\n!ENDQUEST\n!QUIT","0"); 
     98                                 
     99                                final Bindings engineBindings = scriptparser.getContext().getBindings(ScriptContext.ENGINE_SCOPE); 
     100                                 
     101                                engineBindings.put("USER", rquest.getInt("userid")); 
     102                                engineBindings.put("QUEST", "r"+rquest.getInt("id")); 
     103                                engineBindings.put("_PARAMETERS", "0"); 
     104                                try { 
     105                                        scriptparser.eval(":0\n!ENDQUEST\n!QUIT"); 
     106                                } 
     107                                catch( ScriptException e ) { 
     108                                        throw new RuntimeException(e); 
     109                                } 
    98110                                echo.append("Beende Quest bei Spieler "+rquest.getInt("userid")+"<br />\n"); 
    99111                        } 
  • src/net/driftingsouls/ds2/server/modules/schiffplugins/NavigationDefault.java

    r7375108 r28b2039  
    2121import java.util.Iterator; 
    2222import java.util.List; 
     23 
     24import javax.script.Bindings; 
     25import javax.script.ScriptContext; 
     26import javax.script.ScriptEngine; 
    2327 
    2428import net.driftingsouls.ds2.server.ContextCommon; 
     
    106110                if( (ship.getOnMove() != null) && (ship.getOnMove().length() > 0) &&  
    107111                        ((targetx != 0) && (targety != 0)) || ((act != 5) && (act >= 1) && (act <= 9)) ) {       
    108                         ScriptParser scriptparser = ContextMap.getContext().get(ContextCommon.class).getScriptParser( ScriptParser.NameSpace.QUEST ); 
    109                         scriptparser.setShip(ship); 
    110                         scriptparser.setLogFunction(ScriptParser.LOGGER_NULL); 
    111                         scriptparser.setRegister("DIRECTION",Integer.toString(act)); 
    112                         scriptparser.setRegister("MOVEMENTCOUNT",Integer.toString(count)); 
    113                         scriptparser.setRegister("TARGETX",Integer.toString(targetx)); 
    114                         scriptparser.setRegister("TARGETY",Integer.toString(targety)); 
    115                         scriptparser.setRegister("SECTOR", ship.getLocation().toString()); 
     112                        ScriptEngine scriptparser = ContextMap.getContext().get(ContextCommon.class).getScriptParser( "DSQuestScript" ); 
     113                         
     114                        final Bindings engineBindings = scriptparser.getContext().getBindings(ScriptContext.ENGINE_SCOPE); 
     115                         
     116                        engineBindings.put("_SHIP", ship); 
     117                        scriptparser.getContext().setErrorWriter(ScriptParser.LOGGER_NULL); 
     118                        engineBindings.put("DIRECTION",Integer.toString(act)); 
     119                        engineBindings.put("MOVEMENTCOUNT",Integer.toString(count)); 
     120                        engineBindings.put("TARGETX",Integer.toString(targetx)); 
     121                        engineBindings.put("TARGETY",Integer.toString(targety)); 
     122                        engineBindings.put("SECTOR", ship.getLocation().toString()); 
    116123                 
    117124                        Quests.currentEventURL.set("&action=onmove"); 
    118125 
    119                         Quests.executeEvent( scriptparser, ship.getOnMove(), user.getID(), "0" ); 
     126                        Quests.executeEvent( scriptparser, ship.getOnMove(), user, "0", false ); 
    120127                        try { 
    121                                 act = Integer.parseInt(scriptparser.getRegister("DIRECTION")); 
    122                                 count = Integer.parseInt(scriptparser.getRegister("MOVEMENTCOUNT")); 
    123                                 targetx = Integer.parseInt(scriptparser.getRegister("TARGETX")); 
    124                                 targety = Integer.parseInt(scriptparser.getRegister("TARGETY")); 
     128                                act = Integer.parseInt((String)engineBindings.get("DIRECTION")); 
     129                                count = Integer.parseInt((String)engineBindings.get("MOVEMENTCOUNT")); 
     130                                targetx = Integer.parseInt((String)engineBindings.get("TARGETX")); 
     131                                targety = Integer.parseInt((String)engineBindings.get("TARGETY")); 
    125132                        } 
    126133                        catch( NumberFormatException e ) { 
  • src/net/driftingsouls/ds2/server/scripting/QuestFunctions.java

    r2d1909f r28b2039  
    1919package net.driftingsouls.ds2.server.scripting; 
    2020 
     21import java.io.IOException; 
    2122import java.sql.Blob; 
    2223import java.util.ArrayList; 
     
    2728 
    2829import javax.script.ScriptContext; 
     30import javax.script.ScriptException; 
    2931 
    3032import net.driftingsouls.ds2.server.ContextCommon; 
     
    189191                        String text = bbcodeparser.parse(dialogText); 
    190192                         
    191                         ScriptParserContext context = scriptparser.getContext(); 
    192                         context.out( "<table class=\"noBorderX\"><tr><td class=\"noBorderX\" valign=\"top\">" ); 
    193                         context.out( "<img src=\""+Configuration.getSetting("URL")+"data/quests/"+dialogImage+"\" alt=\"\" />" ); 
    194                         context.out( "</td><td class=\"noBorderX\" valign=\"top\">" ); 
    195                         context.out( StringUtils.replace(text, "\n", "<br />")+"<br /><br />" ); 
    196                          
    197                         for( QuestAnswer answer : dialogAnswers.values() ) {     
    198                                 context.out( "<a class=\"forschinfo\" href=\""+answer.url+"\">"+answer.text+"</a><br />" ); 
    199                         } 
    200                         context.out( "</td></tr></table>" ); 
     193                        ScriptContext context = scriptparser.getContext(); 
     194                        try { 
     195                                context.getWriter().append( "<table class=\"noBorderX\"><tr><td class=\"noBorderX\" valign=\"top\">" ); 
     196                                context.getWriter().append( "<img src=\""+Configuration.getSetting("URL")+"data/quests/"+dialogImage+"\" alt=\"\" />" ); 
     197                                context.getWriter().append( "</td><td class=\"noBorderX\" valign=\"top\">" ); 
     198                                context.getWriter().append( StringUtils.replace(text, "\n", "<br />")+"<br /><br />" ); 
     199                                 
     200                                for( QuestAnswer answer : dialogAnswers.values() ) {     
     201                                        context.getWriter().append( "<a class=\"forschinfo\" href=\""+answer.url+"\">"+answer.text+"</a><br />" ); 
     202                                } 
     203                                context.getWriter().append( "</td></tr></table>" ); 
     204                        } 
     205                        catch( IOException e ) { 
     206                                e.printStackTrace(); 
     207                        } 
    201208                         
    202209                        return CONTINUE; 
     
    686693                        // ggf. das Quest "deinstallieren" (handler entfernen) 
    687694                        if( runningdata.getString("uninstall").length() > 0 ) { 
    688                                 ScriptParserContext context = scriptparser.getContext(); 
     695                                ScriptContext context = scriptparser.getContext(); 
    689696                                 
    690697                                scriptparser.setContext(new ScriptParserContext()); 
    691                                 scriptparser.eval( runningdata.getString("uninstall"), "0" ); 
     698                                scriptparser.getContext().setAttribute("_PARAMETERS", "0", ScriptContext.ENGINE_SCOPE); 
     699                                try { 
     700                                        scriptparser.eval( runningdata.getString("uninstall") ); 
     701                                } 
     702                                catch( ScriptException e ) { 
     703                                        throw new RuntimeException(e); 
     704                                } 
    692705                                 
    693706