--- deliantra/server/include/cfperl.h 2006/08/28 07:07:41 1.11
+++ deliantra/server/include/cfperl.h 2010/04/06 21:11:48 1.118
@@ -1,44 +1,143 @@
+/*
+ * This file is part of Deliantra, the Roguelike Realtime MMORPG.
+ *
+ * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
+ *
+ * Deliantra is free software: you can redistribute it and/or modify it under
+ * the terms of the Affero GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the Affero GNU General Public License
+ * and the GNU General Public License along with this program. If not, see
+ * .
+ *
+ * The authors can be reached via e-mail to
+ */
+
//
// cfperl.h perl interface
//
#ifndef CFPERL_H__
#define CFPERL_H__
-struct pl;
-struct object;
-struct mapstruct;
+using namespace std;
+
+#include
+#include
+#include
+
+#include
+#include
+
+#include "util.h"
+#include "keyword.h"
+#include "dynbuf.h"
+#include "callback.h"
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+// optimisations/workaround for functions requiring my_perl in scope (anti-bloat)
+#undef localtime
+#undef srand48
+#undef drand48
+#undef srandom
+#undef opendir
+#undef readdir
+#undef closedir
+#undef getprotobyname
+#undef gethostbyname
+#undef ctime
+#undef strerror
+#undef _
+
+// same here, massive symbol spamming
+#undef do_open
+#undef do_close
+#undef ref
+#undef seed
+
+// perl bug #40256: perl does overwrite those with reentrant versions
+// but does not initialise their state structures.
+#undef random
+#undef crypt
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+#define _(msg) (msg)
+#define N_(msg) (msg)
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+// some macros to simplify perl in-calls
+
+#define CHECK_ERROR \
+ if (SvTRUE (ERRSV)) \
+ LOG (llevError, "runtime error in %s: %s", __func__, SvPVutf8_nolen (ERRSV));
+
+inline int call_pvsv (const char *ob, I32 flags) { return call_pv (ob, flags); }
+inline int call_pvsv (SV *ob, I32 flags) { return call_sv (ob, flags); }
+
+#define CALL_BEGIN(args) dSP; ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, args)
+#define CALL_ARG_SV(sv) PUSHs (sv_2mortal (sv)) // separate because no refcount inc
+#define CALL_ARG(expr) PUSHs (sv_2mortal (to_sv (expr)))
+#define CALL_CALL(name, flags) PUTBACK; int count = call_pvsv (name, (flags) | G_EVAL); SPAGAIN;
+#define CALL_END PUTBACK; CHECK_ERROR; FREETMPS; LEAVE
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void cfperl_init ();
void cfperl_main ();
+void cfperl_tick ();
+void cfperl_emergency_save ();
+void cfperl_cleanup (int make_core);
+void cfperl_make_book (object *book, int level);
+void cfperl_send_msg (client *ns, int color, const_utf8_string type, const_utf8_string msg);
+int cfperl_can_merge (object *ob1, object *ob2);
+void cfperl_mapscript_activate (object *ob, int state, object *activator, object *originator = 0);
+
+bool is_match_expr (const_utf8_string expr);
+// applies the match expression and returns true if it matches
+bool match (const_utf8_string expr, object *ob, object *self = 0, object *source = 0, object *originator = 0);
+// same as above, but returns the first object found, or 0
+object *match_one (const_utf8_string expr, object *ob, object *self = 0, object *source = 0, object *originator = 0);
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+#if IVSIZE >= 8
+ typedef IV val64;
+ typedef IV uval64;
+# define newSVval64 newSViv
+# define SvVAL64 SvIV
+# define newSVuval64 newSVuv
+# define SvUVAL64 SvUV
+#else
+ typedef double val64;
+ typedef double uval64;
+# define newSVval64 newSVnv
+# define SvVAL64 SvNV
+# define newSVuval64 newSVnv
+# define SvUVAL64 SvNV
+#endif
-// could have used templates, but a more traditional C api
-// uses more explicit typing which is ok for this purpose.
-enum data_type
-{
- DT_END, // no further arguments
- DT_AV, // perl-only av that needs to be flattened out
- DT_INT,
- DT_INT64,
- DT_DOUBLE,
- DT_STRING, // 0-terminated string
- DT_DATA, // string + length
- DT_OBJECT,
- DT_MAP,
- DT_PLAYER,
- DT_ARCH,
- DT_PARTY,
- DT_REGION,
-
- NUM_DATA_TYPES
-};
+extern tstamp runtime; // virtual server time, excluding time jumps and lag
+extern tstamp NOW; // real time of current server tick
enum event_klass
{
KLASS_NONE,
KLASS_GLOBAL,
+ KLASS_ATTACHABLE,
+ KLASS_CLIENT,
KLASS_PLAYER,
KLASS_OBJECT,
KLASS_MAP,
+ KLASS_COMMAND,
};
enum event_type
@@ -49,100 +148,457 @@
NUM_EVENT_TYPES
};
-#define ARG_AV(o) DT_AV , static_cast (o)
-#define ARG_INT(v) DT_INT , static_cast (v)
-#define ARG_INT64(v) DT_INT64 , static_cast (v)
-#define ARG_DOUBLE(v) DT_DOUBLE, static_cast (v)
-#define ARG_STRING(v) DT_STRING, static_cast (v)
-#define ARG_DATA(s,l) DT_DATA , static_cast (s), (l)
-#define ARG_OBJECT(o) DT_OBJECT, (void *)static_cast (o)
-#define ARG_MAP(o) DT_MAP , (void *)static_cast (o)
-#define ARG_PLAYER(o) DT_PLAYER, (void *)static_cast (o)
-#define ARG_ARCH(o) DT_ARCH , (void *)static_cast (o)
-#define ARG_PARTY(o) DT_PARTY , (void *)static_cast (o)
-#define ARG_REGION(o) DT_REGION, (void *)static_cast (o)
+// in which global events or per-type events are we interested
+extern bitset ev_want_event;
+extern bitset ev_want_type;
+
+#define ARG_AV(o) DT_AV , static_cast (o)
+#define ARG_INT(v) DT_INT , static_cast (v)
+#define ARG_INT64(v) DT_INT64 , static_cast (v)
+#define ARG_DOUBLE(v) DT_DOUBLE, static_cast (v)
+#define ARG_STRING(v) DT_STRING, static_cast (v)
+#define ARG_DATA(s,l) DT_DATA , static_cast (s), int (l)
+#define ARG_OBJECT(o) DT_OBJECT, (void *)(static_cast