… | |
… | |
494 | |
494 | |
495 | void * |
495 | void * |
496 | globalEventListener (int *type, ...) |
496 | globalEventListener (int *type, ...) |
497 | { |
497 | { |
498 | va_list args; |
498 | va_list args; |
499 | static int rv = 0; |
499 | static int rv; |
500 | CFPContext context; |
500 | int event_code; |
501 | char *buf; |
|
|
502 | player *pl; |
|
|
503 | object *op; |
|
|
504 | |
501 | |
505 | if (!perl) |
502 | if (!perl) |
506 | return; |
503 | return; |
507 | |
504 | |
508 | memset (&context, 0, sizeof (context)); |
|
|
509 | |
|
|
510 | va_start (args, type); |
505 | va_start (args, type); |
511 | context.event_code = va_arg (args, int); |
506 | event_code = va_arg (args, int); |
512 | |
507 | |
513 | switch (context.event_code) |
508 | if (event_code == EVENT_FREE_OB) |
514 | { |
509 | { |
515 | case EVENT_CRASH: |
510 | player *pl; |
516 | printf ("Unimplemented for now\n"); |
511 | object *op; |
517 | break; |
512 | SV *sv; |
518 | |
513 | |
519 | case EVENT_PLAYER_LOAD: |
|
|
520 | case EVENT_PLAYER_SAVE: |
|
|
521 | context.who = va_arg (args, object *); |
514 | op = va_arg (args, object *); |
522 | buf = va_arg (args, char *); |
|
|
523 | if (buf != 0) |
|
|
524 | strncpy (context.message, buf, sizeof (context.message)); |
|
|
525 | break; |
|
|
526 | |
|
|
527 | case EVENT_MAPLOAD: |
|
|
528 | case EVENT_MAPOUT: |
|
|
529 | case EVENT_MAPIN: |
|
|
530 | case EVENT_MAPCLEAN: |
|
|
531 | context.map = va_arg (args, mapstruct *); |
|
|
532 | break; |
|
|
533 | |
|
|
534 | case EVENT_MAPENTER: |
|
|
535 | case EVENT_MAPLEAVE: |
|
|
536 | case EVENT_FREE_OB: |
|
|
537 | case EVENT_BORN: |
|
|
538 | case EVENT_REMOVE: |
|
|
539 | context.activator = va_arg (args, object *); |
|
|
540 | break; |
|
|
541 | |
|
|
542 | case EVENT_PLAYER_DEATH: |
|
|
543 | context.who = va_arg (args, object *); |
|
|
544 | break; |
|
|
545 | |
|
|
546 | case EVENT_GKILL: |
|
|
547 | context.who = va_arg (args, object *); |
|
|
548 | context.activator = va_arg (args, object *); |
|
|
549 | break; |
|
|
550 | |
|
|
551 | case EVENT_LOGIN: |
|
|
552 | case EVENT_LOGOUT: |
|
|
553 | pl = va_arg (args, player *); |
|
|
554 | context.activator = pl->ob; |
|
|
555 | buf = va_arg (args, char *); |
|
|
556 | if (buf != 0) |
|
|
557 | strncpy (context.message, buf, sizeof (context.message)); |
|
|
558 | break; |
|
|
559 | |
|
|
560 | case EVENT_SHOUT: |
|
|
561 | case EVENT_MUZZLE: |
|
|
562 | case EVENT_KICK: |
|
|
563 | context.activator = va_arg (args, object *); |
|
|
564 | buf = va_arg (args, char *); |
|
|
565 | if (buf != 0) |
|
|
566 | strncpy (context.message, buf, sizeof (context.message)); |
|
|
567 | break; |
|
|
568 | |
|
|
569 | case EVENT_CLOCK: |
|
|
570 | clean_obj_cache (); |
|
|
571 | break; |
|
|
572 | |
|
|
573 | case EVENT_TELL: |
|
|
574 | break; |
|
|
575 | |
|
|
576 | case EVENT_MAPRESET: |
|
|
577 | /* stupid, should be the map itself, not "message"??? */ |
|
|
578 | buf = va_arg (args, char *); |
|
|
579 | if (buf != 0) |
|
|
580 | strncpy (context.message, buf, sizeof (context.message)); |
|
|
581 | break; |
|
|
582 | } |
|
|
583 | |
|
|
584 | va_end (args); |
|
|
585 | |
|
|
586 | if (context.event_code == EVENT_FREE_OB) |
|
|
587 | { |
|
|
588 | SV *sv = hv_delete (obj_cache, (char *)&context.activator, sizeof (void *), 0); |
515 | sv = hv_delete (obj_cache, (char *)&op, sizeof (void *), 0); |
589 | |
516 | |
590 | if (sv) |
517 | if (sv) |
591 | clearSVptr (sv); |
518 | clearSVptr (sv); |
|
|
519 | |
|
|
520 | rv = 0; |
592 | } |
521 | } |
593 | else |
522 | else |
594 | inject_event ("cf::inject_global_event", &context); |
523 | { |
595 | |
524 | dSP; |
596 | rv = context.returnvalue; |
525 | |
|
|
526 | ENTER; |
|
|
527 | SAVETMPS; |
|
|
528 | |
|
|
529 | PUSHMARK (SP); |
|
|
530 | |
|
|
531 | EXTEND (SP, 10); |
|
|
532 | PUSHs (sv_2mortal (newSViv (event_code))); |
|
|
533 | |
|
|
534 | #define PUSHcfapi(type,ctype) PUSHs (sv_2mortal (newSVcfapi ((type), va_arg (args, ctype)))) |
|
|
535 | #define PUSH_OB PUSHcfapi(CFAPI_POBJECT, object *) |
|
|
536 | #define PUSH_PL PUSHcfapi(CFAPI_PPLAYER, player *) |
|
|
537 | #define PUSH_MAP PUSHcfapi(CFAPI_PMAP, mapstruct *) |
|
|
538 | #define PUSH_PV PUSHcfapi(CFAPI_STRING, const char *) |
|
|
539 | #define PUSH_IV PUSHcfapi(CFAPI_INT, int) |
|
|
540 | |
|
|
541 | switch (event_code) |
|
|
542 | { |
|
|
543 | case EVENT_CRASH: |
|
|
544 | break; |
|
|
545 | |
|
|
546 | case EVENT_PLAYER_LOAD: |
|
|
547 | case EVENT_PLAYER_SAVE: |
|
|
548 | PUSH_OB; |
|
|
549 | PUSH_PV; |
|
|
550 | break; |
|
|
551 | |
|
|
552 | case EVENT_MAPLOAD: |
|
|
553 | case EVENT_MAPOUT: |
|
|
554 | case EVENT_MAPIN: |
|
|
555 | case EVENT_MAPCLEAN: |
|
|
556 | case EVENT_MAPRESET: |
|
|
557 | PUSH_MAP; |
|
|
558 | break; |
|
|
559 | |
|
|
560 | case EVENT_MAPENTER: |
|
|
561 | case EVENT_MAPLEAVE: |
|
|
562 | case EVENT_BORN: |
|
|
563 | case EVENT_REMOVE: |
|
|
564 | case EVENT_PLAYER_DEATH: |
|
|
565 | PUSH_OB; |
|
|
566 | break; |
|
|
567 | |
|
|
568 | case EVENT_GKILL: |
|
|
569 | PUSH_OB; |
|
|
570 | PUSH_OB; |
|
|
571 | break; |
|
|
572 | |
|
|
573 | case EVENT_LOGIN: |
|
|
574 | case EVENT_LOGOUT: |
|
|
575 | PUSH_PL; |
|
|
576 | PUSH_PV; |
|
|
577 | break; |
|
|
578 | |
|
|
579 | case EVENT_SHOUT: |
|
|
580 | case EVENT_MUZZLE: |
|
|
581 | case EVENT_KICK: |
|
|
582 | PUSH_OB; |
|
|
583 | PUSH_PV; |
|
|
584 | break; |
|
|
585 | |
|
|
586 | case EVENT_CLOCK: |
|
|
587 | clean_obj_cache (); |
|
|
588 | break; |
|
|
589 | |
|
|
590 | case EVENT_TELL: |
|
|
591 | break; |
|
|
592 | } |
|
|
593 | |
|
|
594 | va_end (args); |
|
|
595 | |
|
|
596 | PUTBACK; |
|
|
597 | int count = call_pv ("cf::inject_global_event", G_SCALAR | G_EVAL); |
|
|
598 | SPAGAIN; |
|
|
599 | |
|
|
600 | if (SvTRUE (ERRSV)) |
|
|
601 | LOG (llevError, "event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV)); |
|
|
602 | |
|
|
603 | rv = count > 0 ? POPi : 0; |
|
|
604 | |
|
|
605 | PUTBACK; |
|
|
606 | FREETMPS; |
|
|
607 | LEAVE; |
|
|
608 | } |
597 | |
609 | |
598 | return &rv; |
610 | return &rv; |
599 | } |
611 | } |
600 | |
612 | |
601 | void * |
613 | void * |
… | |
… | |
603 | { |
615 | { |
604 | static int rv = 0; |
616 | static int rv = 0; |
605 | va_list args; |
617 | va_list args; |
606 | char *buf; |
618 | char *buf; |
607 | CFPContext context; |
619 | CFPContext context; |
|
|
620 | object *eob; |
608 | |
621 | |
609 | if (!perl) |
622 | if (!perl) |
610 | return; |
623 | return; |
611 | |
624 | |
612 | memset (&context, 0, sizeof (context)); |
625 | memset (&context, 0, sizeof (context)); |
… | |
… | |
623 | strncpy (context.message, buf, sizeof (context.message)); |
636 | strncpy (context.message, buf, sizeof (context.message)); |
624 | |
637 | |
625 | context.fix = va_arg (args, int); |
638 | context.fix = va_arg (args, int); |
626 | strncpy (context.extension, va_arg (args, char *), sizeof (context.extension)); |
639 | strncpy (context.extension, va_arg (args, char *), sizeof (context.extension)); |
627 | strncpy (context.options, va_arg (args, char *), sizeof (context.options)); |
640 | strncpy (context.options, va_arg (args, char *), sizeof (context.options)); |
|
|
641 | eob = va_arg (args, object *); |
628 | context.returnvalue = 0; |
642 | context.returnvalue = 0; |
629 | va_end (args); |
643 | va_end (args); |
630 | |
644 | |
631 | inject_event ("cf::inject_event", &context); |
645 | inject_event ("cf::inject_event", &context); |
632 | |
646 | |