Add commands for changing status and nick
This commit is contained in:
parent
c2d021534f
commit
80b91d872d
|
@ -432,6 +432,8 @@ void read_status(void) {
|
||||||
errx(1, "Frontend sent a nick with malformed utf-8 or control characters");
|
errx(1, "Frontend sent a nick with malformed utf-8 or control characters");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
own_status = status;
|
||||||
|
|
||||||
memcpy(own_nick, nick, length);
|
memcpy(own_nick, nick, length);
|
||||||
own_nick_length = length;
|
own_nick_length = length;
|
||||||
}
|
}
|
||||||
|
@ -473,6 +475,7 @@ void read_command(void) {
|
||||||
send_status_request(mac);
|
send_status_request(mac);
|
||||||
} else if (cmd == 's') {
|
} else if (cmd == 's') {
|
||||||
read_status();
|
read_status();
|
||||||
|
send_status(broadcast_mac);
|
||||||
} else if (cmd == 'm') {
|
} else if (cmd == 'm') {
|
||||||
read_message();
|
read_message();
|
||||||
} else {
|
} else {
|
||||||
|
|
35
ethermess.py
35
ethermess.py
|
@ -5,6 +5,9 @@ import select
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
own_nick = None
|
||||||
|
own_status = None
|
||||||
|
|
||||||
def writeall(f, b):
|
def writeall(f, b):
|
||||||
written = 0
|
written = 0
|
||||||
while written < len(b):
|
while written < len(b):
|
||||||
|
@ -55,7 +58,13 @@ def send_message(backend, mac, message):
|
||||||
def send_status_request(backend, mac):
|
def send_status_request(backend, mac):
|
||||||
writeall(backend, b'r' + mac)
|
writeall(backend, b'r' + mac)
|
||||||
|
|
||||||
|
def set_status_nick(backend, status, nick):
|
||||||
|
encoded = nick.encode('utf-8')
|
||||||
|
writeall(backend, b's' + bytes([status, len(encoded)]) + encoded)
|
||||||
|
|
||||||
def handle_user_command(backend, line):
|
def handle_user_command(backend, line):
|
||||||
|
global own_nick, own_status
|
||||||
|
|
||||||
if len(line) > 0 and line[0] == '/':
|
if len(line) > 0 and line[0] == '/':
|
||||||
command, _, rest = line.partition(' ')
|
command, _, rest = line.partition(' ')
|
||||||
if command == '/msg':
|
if command == '/msg':
|
||||||
|
@ -69,13 +78,25 @@ def handle_user_command(backend, line):
|
||||||
mac = parse_mac(rest)
|
mac = parse_mac(rest)
|
||||||
send_status_request(backend, mac)
|
send_status_request(backend, mac)
|
||||||
|
|
||||||
|
elif command == '/available' and rest == '':
|
||||||
|
own_status = 0
|
||||||
|
set_status_nick(backend, own_status, own_nick)
|
||||||
|
|
||||||
|
elif command == '/unavailable' and rest == '':
|
||||||
|
own_status = 1
|
||||||
|
set_status_nick(backend, own_status, own_nick)
|
||||||
|
|
||||||
|
elif command == '/nick':
|
||||||
|
own_nick = rest
|
||||||
|
set_status_nick(backend, own_status, own_nick)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Display usage
|
# Display usage
|
||||||
print('/msg <MAC> <message>; /status <MAC>')
|
print('/msg <MAC> <message>; /status <MAC>; /available; /unavailable; /nick')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Display usage
|
# Display usage
|
||||||
print('/msg <MAC> <message>; /status <MAC>')
|
print('/msg <MAC> <message>; /status <MAC>; /available; /unavailable; /nick')
|
||||||
|
|
||||||
def eventloop(proc):
|
def eventloop(proc):
|
||||||
# Create unbuffered version of stdin
|
# Create unbuffered version of stdin
|
||||||
|
@ -163,14 +184,16 @@ def eventloop(proc):
|
||||||
else:
|
else:
|
||||||
raise Exception('Unreachable')
|
raise Exception('Unreachable')
|
||||||
def main():
|
def main():
|
||||||
_, interface, nick = sys.argv
|
global own_nick, own_status
|
||||||
|
|
||||||
|
_, interface, own_nick = sys.argv
|
||||||
|
|
||||||
proc = subprocess.Popen(['sudo', libexec_dir + '/ethermess-backend', interface], stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = sys.stderr, bufsize = 0)
|
proc = subprocess.Popen(['sudo', libexec_dir + '/ethermess-backend', interface], stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = sys.stderr, bufsize = 0)
|
||||||
|
|
||||||
# Tell the backend the status and nick
|
# Tell the backend the status and nick
|
||||||
status = 0
|
own_status = 0
|
||||||
nick = nick.encode('utf-8')
|
encoded = own_nick.encode('utf-8')
|
||||||
writeall(proc.stdin, bytes([status, len(nick)]) + nick)
|
writeall(proc.stdin, bytes([own_status, len(encoded)]) + encoded)
|
||||||
|
|
||||||
# Read our MAC
|
# Read our MAC
|
||||||
mac = readall(proc.stdout, 6)
|
mac = readall(proc.stdout, 6)
|
||||||
|
|
Loading…
Reference in New Issue