summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2013-08-04 12:19:25 -0300
committershennetsind <ind@henn.et>2013-08-08 15:07:40 -0300
commit6b9f58446c46877ecfc5fe40847636145acf5af8 (patch)
tree81b71aa95a47e611a5415528cf72efefe0d552b1 /src/plugins
parentdefac0ef9714121a872ab48c3f6c4ddd177ae509 (diff)
downloadhercules-6b9f58446c46877ecfc5fe40847636145acf5af8.tar.gz
hercules-6b9f58446c46877ecfc5fe40847636145acf5af8.tar.bz2
hercules-6b9f58446c46877ecfc5fe40847636145acf5af8.tar.xz
hercules-6b9f58446c46877ecfc5fe40847636145acf5af8.zip
HPM Update
- Custom Packet Support - Custom Data Struct Support (currently append-able to map_session_data and socket_data) - Char Server Support - Login Server Support http://hercules.ws/board/topic/1934-hercules-plugin-manager-update/ Documentation will soon be updated in http://hercules.ws/wiki/HPM Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/sample.c82
1 files changed, 78 insertions, 4 deletions
diff --git a/src/plugins/sample.c b/src/plugins/sample.c
index 7f7528cb7..4a8402560 100644
--- a/src/plugins/sample.c
+++ b/src/plugins/sample.c
@@ -4,9 +4,15 @@
#include <stdio.h>
#include <string.h>
+#include <stdlib.h>
+
#include "../common/HPMi.h"
+#include "../common/mmo.h"
+#include "../common/socket.h"
+#include "../common/malloc.h"
#include "../map/script.h"
#include "../map/pc.h"
+#include "../map/clif.h"
HPExport struct hplugin_info pinfo = {
"Sample", // Plugin name
@@ -26,18 +32,81 @@ BUILDIN(sample) {//script command 'sample(num);' - 1 param: struct script_state*
CPCMD(sample) {//console command 'sample' - 1 param: char *line
ShowInfo("I'm being run! arg -> '%s'\n",line?line:"NONE");
}
-struct script_interface *script;/* used by script commands */
+struct sample_data_struct {
+ struct point lastMSGPosition;
+ unsigned int someNumber;
+};
+/* sample packet implementation */
+/* cmd 0xf3 - it is a client-server existent id, for clif_parse_GlobalMessage */
+/* in this sample we do nothing and simply redirect */
+void sample_packet0f3(int fd) {
+ struct map_session_data *sd = session[fd]->session_data;
+ struct sample_data_struct *data;
+
+ if( !sd ) return;/* socket didn't fully log-in? this packet shouldn't do anything then! */
+
+ ShowInfo("sample_packet0f3: Hello World! received 0xf3 for '%s', redirecting!\n",sd->status.name);
+
+ /* sample usage of appending data to a socket_data (session[]) entry */
+ if( !(data = HPMi->getFromSession(session[fd],HPMi->pid,0)) ) {
+ CREATE(data,struct sample_data_struct,1);
+
+ data->lastMSGPosition.map = sd->status.last_point.map;
+ data->lastMSGPosition.x = sd->status.last_point.x;
+ data->lastMSGPosition.y = sd->status.last_point.y;
+ data->someNumber = rand()%777;
+
+ ShowInfo("Created Appended session[] data, %d %d %d %d\n",data->lastMSGPosition.map,data->lastMSGPosition.x,data->lastMSGPosition.y,data->someNumber);
+ HPMi->addToSession(session[fd],data,HPMi->pid,0,true);
+ } else {
+ ShowInfo("Existent Appended session[] data, %d %d %d %d\n",data->lastMSGPosition.map,data->lastMSGPosition.x,data->lastMSGPosition.y,data->someNumber);
+ if( rand()%4 == 2 ) {
+ ShowInfo("Removing Appended session[] data\n");
+ HPMi->removeFromSession(session[fd],HPMi->pid,0);
+ }
+ }
+
+ /* sample usage of appending data to a map_session_data (sd) entry */
+ if( !(data = HPMi->getFromMSD(sd,HPMi->pid,0)) ) {
+ CREATE(data,struct sample_data_struct,1);
+
+ data->lastMSGPosition.map = sd->status.last_point.map;
+ data->lastMSGPosition.x = sd->status.last_point.x;
+ data->lastMSGPosition.y = sd->status.last_point.y;
+ data->someNumber = rand()%777;
+
+ ShowInfo("Created Appended map_session_data data, %d %d %d %d\n",data->lastMSGPosition.map,data->lastMSGPosition.x,data->lastMSGPosition.y,data->someNumber);
+ HPMi->addToMSD(sd,data,HPMi->pid,0,true);
+ } else {
+ ShowInfo("Existent Appended map_session_data data, %d %d %d %d\n",data->lastMSGPosition.map,data->lastMSGPosition.x,data->lastMSGPosition.y,data->someNumber);
+ if( rand()%4 == 2 ) {
+ ShowInfo("Removing Appended map_session_data data\n");
+ HPMi->removeFromMSD(sd,HPMi->pid,0);
+ }
+ }
+
+
+ clif->pGlobalMessage(fd,sd);
+}
/* run when server starts */
HPExport void plugin_init (void) {
char *server_type;
char *server_name;
-
- //get the symbols from the server
+
+ /* core vars */
server_type = GET_SYMBOL("SERVER_TYPE");
server_name = GET_SYMBOL("SERVER_NAME");
+ /* core interfaces */
+ iMalloc = GET_SYMBOL("iMalloc");
+
+ /* map-server interfaces */
script = GET_SYMBOL("script");
-
+ clif = GET_SYMBOL("clif");
+
+ /* session[] */
+ session = GET_SYMBOL("session");
+
ShowInfo ("Server type is ");
switch (*server_type) {
@@ -59,6 +128,11 @@ HPExport void plugin_init (void) {
if( HPMi->addCPCommand != NULL ) {//link our 'sample' console command
HPMi->addCPCommand("this:is:a:sample",CPCMD_A(sample));
}
+
+ if( HPMi->addPacket != NULL ) {//link our 'sample' packet to map-server
+ HPMi->addPacket(0xf3,-1,sample_packet0f3,hpClif_Parse,HPMi->pid);
+ }
+
}
/* run when server is ready (online) */
HPExport void server_online (void) {