Author Topic: AutoMessage script that supports more than 1 message  (Read 2208 times)

mRokita

  • Autococker
  • Posts: 598
AutoMessage script that supports more than 1 message
« on: February 10, 2014, 11:26:26 AM »
Hello,
I have written a simple AutoMessage script in python for Superman that supports more than 1 message.
Code: [Select]
import socket
import time
 
host = "83.3.12.43" #your servers ip
port = 1111 #your servers port
rcon_password = "rcon_password" #your servers rcon password
command = "say" #command
interval = 7 #in minutes
messages = ['message 1', 'message 2'] #message list

 
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.connect((host, port))
i = 0
while True:
   print("Sending..")
   sock.send("\xFF\xFF\xFF\xFFrcon %s %s %s\0" % (rcon_password, command, messages[i%len(messages)]));
   i=i+1
   time.sleep(60*interval)
« Last Edit: January 09, 2016, 09:52:06 AM by mRokita »

SuperMAn

  • Committee Member
  • Autococker
  • Posts: 902
Re: AutoMessage script that supports more than 1 message
« Reply #1 on: February 12, 2014, 10:43:40 AM »
Thanks, it works well.

Like I said on irc:  If you get bored again it would be nice if this script could also support multiple servers.   :)

not_payl_obviously

  • 68 Carbine
  • Posts: 415
Re: AutoMessage script that supports more than 1 message
« Reply #2 on: February 12, 2014, 11:44:10 AM »
Btw. nobody likes when his console is spammed with pointless messages. Just take it out, it does not make any good.

xrichardx

  • 68 Carbine
  • Posts: 295
Re: AutoMessage script that supports more than 1 message
« Reply #3 on: February 12, 2014, 11:54:37 AM »
@M1CH43L: you should add that this only works with python 2, python 3 will require encrypting the string.
If you get bored again it would be nice if this script could also support multiple servers.   :)
I dont know if he minds other people modifying his source, but simply replacing the vars with a list you can loop through will do that:
Code: [Select]
import socket
import time
 
servers = [
    # syntax:       ("<ip>", <port>, "<password>"),
    # example line: ("12.34.45.67", 27910, "password"),
    ("12.34.45.67", 27911, "password"),
    ]

command = "say" #command
interval = 7 #in minutes
messages = ['message 1', 'message 2'] #message list


sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
i = 0

while True:
   for server in servers:
      print("Sending to " + server[0] + ":" + str(server[1]))
      sock.sendto("\xFF\xFF\xFF\xFFrcon %s %s %s\0" % (server[2], command, messages[i%len(messages)]), (server[0], server[1]) );

   i=i+1
   time.sleep(60*interval)
« Last Edit: February 12, 2014, 12:36:02 PM by xrichardx »

SuperMAn

  • Committee Member
  • Autococker
  • Posts: 902
Re: AutoMessage script that supports more than 1 message
« Reply #4 on: February 12, 2014, 12:32:58 PM »
Thanks xrichardx.  I will test it out later.

mRokita

  • Autococker
  • Posts: 598
Re: AutoMessage script that supports more than 1 message
« Reply #5 on: February 12, 2014, 02:49:27 PM »
Nice script, xrichardx.
I dont have anything to editing my script, but it would be nice to ask me first ;).