From 12fc5ad64f095594f79a12ab860b3ef160248a76 Mon Sep 17 00:00:00 2001 From: turleypol Date: Mon, 16 Mar 2026 08:57:33 +0100 Subject: [PATCH] renamed SendEmail function since its now a corefunction added new events --- .../Email/commands/admin/testsmtp.src | 22 +- pkg/connectors/Email/include/emailer.inc | 208 ++++++++++-------- scripts/include/sysEvent.inc | 13 +- 3 files changed, 131 insertions(+), 112 deletions(-) diff --git a/pkg/connectors/Email/commands/admin/testsmtp.src b/pkg/connectors/Email/commands/admin/testsmtp.src index dd621266d..b88496b8c 100644 --- a/pkg/connectors/Email/commands/admin/testsmtp.src +++ b/pkg/connectors/Email/commands/admin/testsmtp.src @@ -1,17 +1,19 @@ -Use uo; +use uo; use os; use cfgfile; use file; include ":email:emailer"; -program textcmd_testsmtp(who) - - var toAddress := RequestInput(who, who.backpack, "Enter email address:" ); - var outbound := SendEmail( toAddress, "Test Email from UO Server", "Test was successful"); - - if(outbound == error) - SendsysMessage( who, outbound.errortext ); - endif +program textcmd_testsmtp( who ) + + var toAddress := RequestInput( who, who.backpack, "Enter email address:" ); + var outbound := SendEmailDeprecated( toAddress, "Test Email from UO Server", + "Test was successful" ); + + if ( outbound == error ) + SendsysMessage( who, outbound.errortext ); + endif + +endprogram -endprogram \ No newline at end of file diff --git a/pkg/connectors/Email/include/emailer.inc b/pkg/connectors/Email/include/emailer.inc index a7945c813..f0264dbe5 100644 --- a/pkg/connectors/Email/include/emailer.inc +++ b/pkg/connectors/Email/include/emailer.inc @@ -3,17 +3,17 @@ * Purpose * Provide a single function to be able to quickly send email from within the server without external programs. * (Excluding an SMTP server) - * + * * Created by Dev GIB * */ use uo; use os; - /* - * SendEmail( ToAddress, Subject, Body, Modifiers) + * SendEmailDeprecated( ToAddress, Subject, Body, Modifiers) * + * Deprecated: use os::SendEmail * Purpose * Sends an email to address or addresses based on information given to the function. * Multiple emails can be defined for any given email field, its important to seperate with a semicolon @@ -35,70 +35,81 @@ use os; * Failure - Returns error message. * */ -function SendEmail( ToEmail, Subject, Body, Modifiers:=0) - - var settings_cfg := ReadConfigFile(":emailer:settings"); - if( settings_cfg.errortext ) - SysLog("Error::SendEmail() - Unable to open [:emailer:settings.cfg] ->"+settings_cfg.errortext); - return error{"errortext" := "Unable to open [:emailer:settings.cfg]"}; - endif - - var cfg_elem := FindConfigElem( settings_cfg, "Settings" ); - - var smtpHost := GetConfigString( cfg_elem, "host" ); - var LoggingLevel := cInt(GetConfigString( cfg_elem, "LoggingLevel" )); - if( LoggingLevel == error ) - LogToFile("::log/emailer.log", "Error::SendEmail() - Logging level config not found or incorrect.", LOG_DATETIME); - endif - if( smtpHost == error ) - if( LoggingLevel >= 1 ) - LogToFile("::log/emailer.log", "Error::SendEmail() - SMTP host config not found or incorrect.", LOG_DATETIME); - endif - return error{"errortext" := "SMTP host config not found or incorrect."}; - endif - var smtpPort := GetConfigString( cfg_elem, "port" ); - if( smtpPort == error ) - if( LoggingLevel >= 1 ) - LogToFile("::log/emailer.log", "Error::SendEmail() - SMTP port config not found or incorrect.", LOG_DATETIME); - endif - return error{"errortext" := "SMTP port config not found or incorrect."}; - endif - - if( !Modifiers ) - Modifiers := struct{}; - Modifiers.FromEmail := ""; - Modifiers.ToContactName := ""; - Modifiers.CC := ""; - Modifiers.BCC := ""; - Modifiers.ReplyTo := ""; - endif - - if( !Modifiers.FromEmail ) - Modifiers.FromEmail := GetConfigString( cfg_elem, "FromEmail" );//Sets the FromEmail to the default FromEmail in the config file. - endif - - - if( ValidateEmail( ToEmail ) != 1 ) - if( LoggingLevel >= 1 ) - LogToFile("::log/emailer.log", "Error::SendEmail() - ToEmail is not valid: "+ToEmail, LOG_DATETIME); - endif - return error{"errortext":="ToEmail is not valid."}; - endif - if( ValidateEmail( Modifiers.FromEmail ) != 1 ) - if( LoggingLevel >= 1 ) - LogToFile("::log/emailer.log", "Error::SendEmail() - Modifiers.FromEmail is not valid: "+Modifiers.FromEmail, LOG_DATETIME); - endif - return error{"errortext":="FromAddress is not valid."}; - endif - - var EmailCommand := BuildEmailStruct( ToEmail, Subject, Body, Modifiers ); - if( LoggingLevel > 0 ) EmailCommand.LL := LoggingLevel; endif - var connection := OpenConnection( smtpHost, cint(smtpPort), ":emailer:sendEmail", EmailCommand, 1 ); - if( connection == error ) - return connection; - endif - return 1; - +function SendEmailDeprecated( ToEmail, Subject, Body, Modifiers := 0 ) + + var settings_cfg := ReadConfigFile( ":emailer:settings" ); + if ( settings_cfg.errortext ) + SysLog( "Error::SendEmail() - Unable to open [:emailer:settings.cfg] ->" + settings_cfg.errortext ); + return error{ "errortext" := "Unable to open [:emailer:settings.cfg]" }; + endif + + var cfg_elem := FindConfigElem( settings_cfg, "Settings" ); + + var smtpHost := GetConfigString( cfg_elem, "host" ); + var LoggingLevel := cInt( GetConfigString( cfg_elem, "LoggingLevel" ) ); + if ( LoggingLevel == error ) + LogToFile( "::log/emailer.log", + "Error::SendEmail() - Logging level config not found or incorrect.", + LOG_DATETIME ); + endif + if ( smtpHost == error ) + if ( LoggingLevel >= 1 ) + LogToFile( "::log/emailer.log", + "Error::SendEmail() - SMTP host config not found or incorrect.", + LOG_DATETIME ); + endif + return error{ "errortext" := "SMTP host config not found or incorrect." }; + endif + var smtpPort := GetConfigString( cfg_elem, "port" ); + if ( smtpPort == error ) + if ( LoggingLevel >= 1 ) + LogToFile( "::log/emailer.log", + "Error::SendEmail() - SMTP port config not found or incorrect.", + LOG_DATETIME ); + endif + return error{ "errortext" := "SMTP port config not found or incorrect." }; + endif + + if ( !Modifiers ) + Modifiers := struct{}; + Modifiers.FromEmail := ""; + Modifiers.ToContactName := ""; + Modifiers.CC := ""; + Modifiers.BCC := ""; + Modifiers.ReplyTo := ""; + endif + + if ( !Modifiers.FromEmail ) + Modifiers.FromEmail := GetConfigString( cfg_elem, "FromEmail" ); // Sets the FromEmail to the default FromEmail in the config file. + endif + + if ( ValidateEmail( ToEmail ) != 1 ) + if ( LoggingLevel >= 1 ) + LogToFile( "::log/emailer.log", "Error::SendEmail() - ToEmail is not valid: " + + ToEmail, LOG_DATETIME ); + endif + return error{ "errortext" := "ToEmail is not valid." }; + endif + if ( ValidateEmail( Modifiers.FromEmail ) != 1 ) + if ( LoggingLevel >= 1 ) + LogToFile( "::log/emailer.log", + "Error::SendEmail() - Modifiers.FromEmail is not valid: " + + Modifiers.FromEmail, LOG_DATETIME ); + endif + return error{ "errortext" := "FromAddress is not valid." }; + endif + + var EmailCommand := BuildEmailStruct( ToEmail, Subject, Body, Modifiers ); + if ( LoggingLevel > 0 ) + EmailCommand.LL := LoggingLevel; + endif + var connection := OpenConnection( smtpHost, cint( smtpPort ), + ":emailer:sendEmail", EmailCommand, 1 ); + if ( connection == error ) + return connection; + endif + return 1; + endfunction /* @@ -121,23 +132,21 @@ function ValidateEmail( Address ) var HasAtSymbol := 0; var HasFullStop := 0; var i; - - for ( i:= 1; i< address.length(); i:=i+1) - if( HasAtSymbol == 1 && HasFullStop == 1 ) - return 1; + + for ( i := 1; i < address.length(); i := i + 1 ) + if ( HasAtSymbol == 1 && HasFullStop == 1 ) + return 1; + endif + if ( address[i] == "@" ) + HasAtSymbol := 1; + elseif ( address[i] == "." ) + HasFullStop := 1; endif - if ( address[i] == "@" ) - HasAtSymbol := 1; - elseif( address[i] == "." ); - HasFullStop := 1; - endif endfor - - return 0; - -endfunction + return 0; +endfunction /* * BuildEmailStruct( ToEmail, Subject, Body, Modifiers ) @@ -164,18 +173,27 @@ endfunction */ function BuildEmailStruct( ToEmail, Subject, Body, Modifiers ) - - var TempStruct := struct{}; - - TempStruct.ToEmail := ToEmail; - TempStruct.Subject := Subject; - TempStruct.Body := Body; - TempStruct.FromEmail := Modifiers.FromEmail; - if( Modifiers.ToContactName ) TempStruct.ToContactName := Modifiers.ToContactName; endif - if( Modifiers.CC ) TempStruct.CC := Modifiers.CC; endif - if( Modifiers.BCC ) TempStruct.BCC := Modifiers.BCC;endif - if( Modifiers.ReplyTo ) TempStruct.ReplyTo := Modifiers.ReplyTo; endif - - return TempStruct; - -endfunction \ No newline at end of file + + var TempStruct := struct{}; + + TempStruct.ToEmail := ToEmail; + TempStruct.Subject := Subject; + TempStruct.Body := Body; + TempStruct.FromEmail := Modifiers.FromEmail; + if ( Modifiers.ToContactName ) + TempStruct.ToContactName := Modifiers.ToContactName; + endif + if ( Modifiers.CC ) + TempStruct.CC := Modifiers.CC; + endif + if ( Modifiers.BCC ) + TempStruct.BCC := Modifiers.BCC; + endif + if ( Modifiers.ReplyTo ) + TempStruct.ReplyTo := Modifiers.ReplyTo; + endif + + return TempStruct; + +endfunction + diff --git a/scripts/include/sysEvent.inc b/scripts/include/sysEvent.inc index 16da1aa28..561739192 100644 --- a/scripts/include/sysEvent.inc +++ b/scripts/include/sysEvent.inc @@ -11,7 +11,7 @@ // // - +// format-off const SYSEVENT_SPEECH := 0x00000001; const SYSEVENT_ENGAGED := 0x00000002; @@ -22,8 +22,6 @@ const SYSEVENT_DAMAGED := 0x00000008; const SYSEVENT_ENTEREDAREA := 0x00000010; const SYSEVENT_LEFTAREA := 0x00000020; -const SYSEVENT_GONE_CRIMINAL := 0x2000; - const SYSEVENT_OPPONENT_MOVED := 0x00000040; const SYSEVENT_HOSTILE_MOVED := 0x00000080; // not implemented @@ -36,12 +34,12 @@ const SYSEVENT_ITEM_GIVEN := 0x00000400; const SYSEVENT_DOUBLECLICKED := 0x00000800; const SYSEVENT_GHOST_SPEECH := 0x00001000; -const SYSEVENT_RESERVED_00002000 := 0x00002000; -const SYSEVENT_TOKEN_SPEECH := 0x00004000; +const SYSEVENT_GONE_CRIMINAL := 0x00002000; +const SYSEVENT_TOKEN_SPEECH := 0x00004000; const SYSEVENT_TOKEN_GHOST_SPEECH := 0x00008000; +const SYSEVENT_BOAT_MOVEMENT := 0x00010000; +const SYSEVENT_GUMP_RESPONSE := 0x00020000; -const SYSEVENT_RESERVED_00010000 := 0x00010000; -const SYSEVENT_RESERVED_00020000 := 0x00020000; const SYSEVENT_RESERVED_00040000 := 0x00040000; const SYSEVENT_RESERVED_00080000 := 0x00080000; const SYSEVENT_RESERVED_00100000 := 0x00100000; @@ -56,3 +54,4 @@ const SYSEVENT_RESERVED_10000000 := 0x10000000; const SYSEVENT_RESERVED_20000000 := 0x20000000; const SYSEVENT_RESERVED_40000000 := 0x40000000; const SYSEVENT_RESERVED_80000000 := 0x80000000; +