Difference between revisions of "Manual:DIL Manual/send()"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
 
Line 1: Line 1:
 +
= send =
  
 +
The '''send''' function is a built-in DIL (DikuMUD Interactive Language) function that sends a message to all DIL programs in the current local environment that are waiting for messages of the SFB_MSG class.
  
<span id="bpsend"></span>
+
== Syntax ==
  send ( s : string )
+
  send(string message)
    s : Message to send.
 
    result: Send a message to all DIL programs in current local environment,
 
            matching the message class SFB_MSG. The message is not received
 
            by those DIL programs in the local environment that is not set up
 
            to wait for that message class.
 
  
  ---~---~---~---~---~---~---~---~---
+
== Parameters ==
 +
{| class="wikitable"
 +
! Parameter !! Type !! Description
 +
|-
 +
| message || string || The message string to send to waiting DIL programs
 +
|}
 +
 
 +
== Return Value ==
 +
This function does not return a value (void).
 +
 
 +
== Functionality ==
 +
The send function broadcasts a message to all DIL programs in the current local environment that:
 +
* Are currently waiting with the SFB_MSG flag
 +
* Have the message class SFB_MSG enabled
 +
* Are in the same local environment as the sender
 +
 
 +
The message is not received by DIL programs that are not set up to wait for the SFB_MSG message class.
 +
 
 +
== Message Reception ==
 +
When a DIL program receives a message sent via the send() function:
 +
* The program's '''activator''' variable contains a unitptr to the unit that sent the message
 +
* The program's '''argument''' variable contains the string message that was sent
 +
* The command(CMD_AUTO_MSG) evaluates to true
 +
 
 +
== Examples ==
 +
=== Basic Message Sending ===
 +
dilbegin message_sender();
 +
code
 +
  {
 +
    send("hello_world");
 +
    quit;
 +
} dilend
 +
 
 +
=== Jail System Example ===
 +
dilbegin fnpri(FN_PRI_RESCUE-1) jailstay(du : integer);
 +
external
 +
    integer add_reward@justice(criminal_symname : string, criminal_idx : integer, crime_type : integer);
 +
    rem_db_entry@justice(criminal : unitptr, extra_type : string, juris : string);
 +
    getfrom_safe(prisoner : unitptr);
 +
    set_char_flags@justice(char : unitptr, setting : string);
 +
var
 +
    sname : string;
 +
    jd : unitptr;
 +
    id : string;
 +
    juris : string;
 +
    k : string;
 +
    gold : integer;
 +
    g : string;
 +
code
 +
{
 +
    heartbeat := PULSE_SEC * SECS_PER_MUD_HOUR;
 +
    juris := self.outside.zoneidx;
 +
    sname := self.outside.symname;
 +
    jd := findsymbolic("database@justice");
 +
    id := "$reward "+ self.symname + " " + itoa(self.idx) + " "+ juris;
 +
    k := "$reward "+ juris;
 +
    if( "$reward" in self.extra)
 +
    {
 +
      jd.extra.[id].names.[4] := "-1";
 +
      self.extra.[k].names.[4] := "-1";
 +
      jd.extra.[id].descr := self.name+" is currently serving time in jail.";
 +
    }
 +
  :loop:
 +
    pause;
 +
    if (sname != self.outside.symname)
 +
    {
 +
      jd := findsymbolic("database@justice");
 +
      jd.extra.[id].names.[4] := "65";
 +
      self.extra.[k].names.[4] := "65";
 +
      gold := atoi(jd.extra.[id].names.[2]);
 +
      g := moneystring(gold,1);
 +
      jd.extra.[id].descr := "A reward of " + g + " has been offered for the head of "+self.name;
 +
      set_char_flags@justice(self, "wanted");
 +
      log("Jailbreak: "+self.name+" has escaped from the "+ juris +" jail.");
 +
      quit;
 +
    }
 +
    if("$reward" in self.extra)
 +
    {
 +
      jd := findsymbolic("database@justice");
 +
      jd.extra.[id].names.[4] := "-1";
 +
      jd.extra.[id].descr := self.name+" is currently serving time in jail. "+itoa(du)+" hours remaining";
 +
    }
 +
    if ((du % 4) == 0)
 +
      send("jailfood");
 +
    if (du == 24)
 +
    {
 +
      act("At last! The very last day of your term!",
 +
          A_ALWAYS, self, null, null, TO_CHAR);
 +
    }
 +
    else if (du == 12)
 +
    {
 +
      act("Only half a day left 'till your freedom!",
 +
          A_ALWAYS, self, null, null, TO_CHAR);
 +
    }
 +
    else if (du <= 1)
 +
      goto release;
 +
    else
 +
    {
 +
      act("You make another mark on the wall. Only "+itoa(du)+" hours till freedom!",
 +
          A_ALWAYS, self, null, null, TO_CHAR);
 +
    }
 +
    du := du - 1;
 +
    goto loop;
 +
    :release:
 +
    act("Your term is over! You are thrown out of the jail and sent home.",
 +
        A_ALWAYS, self, null, null, TO_CHAR);
 +
    getfrom_safe(self);
 +
    link(self, findroom("accuse_room@" + juris));
 +
    rem_db_entry@justice(self, "$reward", juris);
 +
    set_char_flags@justice(self, "arrest");
 +
    quit;
 +
} dilend
 +
 
 +
=== Message Receiver Example ===
 +
dilbegin message_receiver();
 +
code
 +
{
 +
    wait(SFB_MSG);
 +
    send("Received message: " + argument);
 +
    quit;
 +
} dilend
 +
 
 +
== Error Handling ==
 +
The function performs type checking:
 +
* Validates that the parameter is a string type
 +
* If the parameter is null or invalid, the function fails silently
 +
* The C implementation includes null pointer checking before sending the message
 +
 
 +
Note: The C implementation shows that the function calls dil_test_secure() after sending the message, which may trigger security-related checks.
 +
 
 +
== Usage Notes ==
 +
* Messages are only sent to programs in the same local environment
 +
* Only programs waiting with SFB_MSG will receive the message
 +
* The function is commonly used for inter-program communication
 +
* Use the 'aware' keyword in DIL programs that need to receive messages from their owner
 +
* Use the 'recall' keyword to preserve program state across saves/reloads
 +
* The function is different from sendtext() which sends text directly to a player
 +
 
 +
== Related Functions ==
 +
* [[sendto]] - Sends a message to DIL programs in a specific unit
 +
* [[sendtext]] - Sends text directly to a player
 +
* [[sendtoall]] - Sends a message to all DIL programs in a unit
 +
* [[sendtoalldil]] - Sends a message to all DIL programs in all units
 +
 
 +
== See Also ==
 +
* [[SFB_MSG]] - Message class flag for receiving messages
 +
* [[wait]] - Function for waiting on specific message classes
 +
* [[activator]] - Variable containing the message sender
 +
* [[argument]] - Variable containing the message content

Revision as of 11:20, 29 November 2025

send

The send function is a built-in DIL (DikuMUD Interactive Language) function that sends a message to all DIL programs in the current local environment that are waiting for messages of the SFB_MSG class.

Syntax

send(string message)

Parameters

Parameter Type Description
message string The message string to send to waiting DIL programs

Return Value

This function does not return a value (void).

Functionality

The send function broadcasts a message to all DIL programs in the current local environment that:

  • Are currently waiting with the SFB_MSG flag
  • Have the message class SFB_MSG enabled
  • Are in the same local environment as the sender

The message is not received by DIL programs that are not set up to wait for the SFB_MSG message class.

Message Reception

When a DIL program receives a message sent via the send() function:

  • The program's activator variable contains a unitptr to the unit that sent the message
  • The program's argument variable contains the string message that was sent
  • The command(CMD_AUTO_MSG) evaluates to true

Examples

Basic Message Sending

dilbegin message_sender();
code
{
   send("hello_world");
   quit;
} dilend

Jail System Example

dilbegin fnpri(FN_PRI_RESCUE-1) jailstay(du : integer);
external
   integer add_reward@justice(criminal_symname : string, criminal_idx : integer, crime_type : integer);
   rem_db_entry@justice(criminal : unitptr, extra_type : string, juris : string);
   getfrom_safe(prisoner : unitptr);
   set_char_flags@justice(char : unitptr, setting : string);
var
   sname : string;
   jd : unitptr;
   id : string;
   juris : string; 
   k : string;
   gold : integer;
   g : string;
code
{
   heartbeat := PULSE_SEC * SECS_PER_MUD_HOUR;
   juris := self.outside.zoneidx;
   sname := self.outside.symname;
   jd := findsymbolic("database@justice");
   id := "$reward "+ self.symname + " " + itoa(self.idx) + " "+ juris;
   k := "$reward "+ juris;
   if( "$reward" in self.extra)
   {
      jd.extra.[id].names.[4] := "-1";
      self.extra.[k].names.[4] := "-1";
      jd.extra.[id].descr := self.name+" is currently serving time in jail.";
   }
  :loop:
   pause;
   if (sname != self.outside.symname)
   {
      jd := findsymbolic("database@justice");
      jd.extra.[id].names.[4] := "65";
      self.extra.[k].names.[4] := "65";
      gold := atoi(jd.extra.[id].names.[2]); 
      g := moneystring(gold,1); 
      jd.extra.[id].descr := "A reward of " + g + " has been offered for the head of "+self.name;
      set_char_flags@justice(self, "wanted");
      log("Jailbreak: "+self.name+" has escaped from the "+ juris +" jail."); 
      quit;
   }
   if("$reward" in self.extra)
   {
      jd := findsymbolic("database@justice");
      jd.extra.[id].names.[4] := "-1";
      jd.extra.[id].descr := self.name+" is currently serving time in jail. "+itoa(du)+" hours remaining";
   }
   if ((du % 4) == 0)
     send("jailfood");
   if (du == 24)
   {
      act("At last! The very last day of your term!",
          A_ALWAYS, self, null, null, TO_CHAR);
   }
   else if (du == 12)
   {
      act("Only half a day left 'till your freedom!",
          A_ALWAYS, self, null, null, TO_CHAR);
   }
   else if (du <= 1)
     goto release;
   else
   {
      act("You make another mark on the wall. Only "+itoa(du)+" hours till freedom!",
          A_ALWAYS, self, null, null, TO_CHAR);
   }
   du := du - 1;
   goto loop;
   :release:
   act("Your term is over! You are thrown out of the jail and sent home.",
       A_ALWAYS, self, null, null, TO_CHAR);
   getfrom_safe(self);
   link(self, findroom("accuse_room@" + juris));
   rem_db_entry@justice(self, "$reward", juris);
   set_char_flags@justice(self, "arrest");
   quit;
} dilend

Message Receiver Example

dilbegin message_receiver();
code
{
   wait(SFB_MSG);
   send("Received message: " + argument);
   quit;
} dilend

Error Handling

The function performs type checking:

  • Validates that the parameter is a string type
  • If the parameter is null or invalid, the function fails silently
  • The C implementation includes null pointer checking before sending the message

Note: The C implementation shows that the function calls dil_test_secure() after sending the message, which may trigger security-related checks.

Usage Notes

  • Messages are only sent to programs in the same local environment
  • Only programs waiting with SFB_MSG will receive the message
  • The function is commonly used for inter-program communication
  • Use the 'aware' keyword in DIL programs that need to receive messages from their owner
  • Use the 'recall' keyword to preserve program state across saves/reloads
  • The function is different from sendtext() which sends text directly to a player

Related Functions

  • sendto - Sends a message to DIL programs in a specific unit
  • sendtext - Sends text directly to a player
  • sendtoall - Sends a message to all DIL programs in a unit
  • sendtoalldil - Sends a message to all DIL programs in all units

See Also

  • SFB_MSG - Message class flag for receiving messages
  • wait - Function for waiting on specific message classes
  • activator - Variable containing the message sender
  • argument - Variable containing the message content