Two codebits: Connection Machine and Friend System
-
Because I am in a code blitz mode and am fixing up old code for TheatreMUSH to round out some stuff, I figured I'd post two pieces of code here. These are written and tested in PennMUSH so I cannot guarantee that they will work at all with TinyMUX, though I use mostly common functions and commands so there SHOULD be little issue (maybe with the mail display method, but...).
First, the connection machine. It utilizes a couple of custom functions, header() and isadmin(). header() is pretty straightforward:
[center(%0,78,=)]
And isadmin() is also easy.
[orflags(%0,Wr)]
You can substitute these in the raw code or install them as those functions for shorthand.
First, the connection machine. This controls global aconnect and adisconnects from the Master Room, enabling staff to make things like special messages (MOTDs), a notice when someone logs in every time, wiping guest @mail and +bboards (so guests see all posts as unread) and a lot of other stuff. It includes a default notice (easy to edit), an MOTD command that goes into the notice, guest conn/disconn functions and friend system (further below) conn/disconn messages. As well, if someone sets &bbscan me=1 it'll automatically +bbscan upon connection. This version also includes a mail display of how many mail messages you have.
Probably not something someone already using Theno's codesuite will need, but feel free to pick it apart.
@@ Connection Machine <CM> (#4) @create Connection Machine <CM> @link Connection Machine <CM> = #2 @lock/Basic Connection Machine <CM>=me @lset Connection Machine <CM>/Basic=no_inherit @set Connection Machine <CM> = OPAQUE @set Connection Machine <CM> = WIZARD @set Connection Machine <CM> = SAFE @power Connection Machine <CM> = Cemit @power Connection Machine <CM> = No_Pay &ACONNECT Connection Machine <CM>=@dol lattr(%!/c_*)=@tr %!/%i0=%# @set Connection Machine <CM>/ACONNECT=no_command prefixmatch &ADISCONNECT Connection Machine <CM>=@dol lattr(%!/d_*)=@tr %!/%i0=%# @set Connection Machine <CM>/ADISCONNECT=no_command prefixmatch &AMOVE Connection Machine <CM>=@tel %#=#2 @set Connection Machine <CM>/AMOVE=no_command prefixmatch &C_FRIENDNOTE Connection Machine <CM>=th [iter([mwho()],[if([and([match([xget(%i0,stat`friends)],%0)],[match([xget(%i0,stat`fnotify)],1)])],[pemit(%i0,[ansi(h,<)][ansi(g,Friend System)][ansi(h,>)] [name(%0)] has connected.)])])] &C_GUEST Connection Machine <CM>=th [if(haspower(%0,guest),[wipe(%0/bb_read)][cemit(Guest,<[ansi(hg,Guest)]> [name(%0)] has connected.)])] &C_MAILNOTICE Connection Machine <CM>=th [if([haspower(%0,guest)],,[pemit(%0,[ansi(hb,MAIL: You have [elements(mail(%0),2)] new mail messages.)])])] &CMD_SETMOTD Connection Machine <CM>=$+motd/set *:th [if([isadmin(%#)],[set(%!,motd:%0)][pemit(%#,MOTD: You have set the Message of the Day to '[ansi(hb,%0)]')].,[pemit(%#,MOTD: You are not a member of [mudname()] staff, and cannot do this.)])] &C_NOTICE Connection Machine <CM>=th [pemit(%0,[header(Welcome!)]%R%R[center([ansi(hr,Welcome to [mudname()]!)],78)]%r%R[xget(%!,motd)]%R%R[center(Please keep up with the bboards!,78)]%R[center((+bbscan for unread messages | +help general/bboard for help),78)]%R[header(+help for help)] &C_BBSCAN Connection Machine <CM>=@switch [xget(%0,bbscan)]=1,{@fo %0=+bbscan} &D_FRIENDNOTE Connection Machine <CM>=th [iter([mwho()],[if([and([match([xget(%i0,stat`friends)],%0)],[match([xget(%i0,stat`fnotify)],1)])],[pemit(%i0,[ansi(h,<)][ansi(g,Friend System)][ansi(h,>)] [name(%0)] has disconnected.)])])] &D_GUEST Connection Machine <CM>=@switch [haspower(%0,guest)]=1,{@tel %0=#94;@fo %0=@chan/title guest=} &D_PLACESCLEANUP Connection Machine <CM>=@fo %#=cleanup(%0) &MOTD Connection Machine <CM>=Testing!
Setting a function is as simple as setting a c_attr for connection, or d_attr for disconnect; everything is then parsed with the enactor (the person connecting in 99% of cases) as %0.
Part of this ties into the OTHER piece of code I'm going to post, the Friend System.
The Friend System is pretty much what it says on the tin: you can add/delete people from a specialized friends list, and the connection machine has the added benefit of telling you when they connect/disconnect if it's installed. It'll also give you a master list of all people you've added and if they're connected or not, AND if you want to deny someone, you can deny someone from adding you to their friend list notifications.@@ Friends System v1.0 <FS> (#351) @create Friends System v1.0 <FS> @link Friends System v1.0 <FS> = #2 @set Friends System v1.0 <FS> = WIZARD &AMOVE Friends System v1.0 <FS>=@tel %#=#2 @set Friends System v1.0 <FS>/AMOVE=no_command prefixmatch &CMD Friends System v1.0 <FS>= &CMD`FRIEND_ADD Friends System v1.0 <FS>=$+friend/add *:th [switch([setr(0,[pmatch(%0)])],#-1,[pemit(%#,[ansi(h,<)][ansi(g,Friend System)][ansi(h,>)] That is not a valid player.)],#-2,[pemit(%#,[ansi(h,<)][ansi(g,Friend System)][ansi(h,>)] Too many matches.)],[switch(1,[match([xget(%q0,stat`denyfriend)],%#)],[pemit(%#,[ansi(h,<)][ansi(g,Friend System)][ansi(h,>)] Unable to add that person to your Friends List.)],[match([xget(%#,stat`friends)],%q0)],[pemit(%#,[ansi(h,<)][ansi(g,Friend System)][ansi(h,>)] [name(%q0)] is already in your Friends List.)],[set(%#,stat`friends:[xget(%#,stat`friends)] %q0)][pemit(%#,[ansi(h,<)][ansi(g,Friend System)][ansi(h,>)] [name(%q0)] added to your Friends List.)])])] &CMD`FRIEND_DEL Friends System v1.0 <FS>=$+friend/del *:th [setq(0,[pmatch(%0)])][if([match([xget(%#,stat`friends)],%q0)],[set(%#,stat`friends:[remove([xget(%#,stat`friends)],%q0)])][pemit(%#,[ansi(h,<)][ansi(g,Friend System)][ansi(h,>)] [name(%q0)] removed from your Friends List.)],[pemit(%#,[ansi(h,<)][ansi(g,Friend System)][ansi(h,>)] That person is not in your Friends List.)])] &CMD`FRIEND_DENY Friends System v1.0 <FS>=$+friend/deny *:th [switch([setr(0,[pmatch(%0)])],#-1,[pemit(%#,[ansi(h,<)][ansi(g,Friend System)][ansi(h,>)] That is not a valid player.)],#-2,[pemit(%#,[ansi(h,<)][ansi(g,Friend System)][ansi(h,>)] Too many matches.)],[if([match([xget(%#,stat`denyfriend)],%q0)],[pemit(%#,[ansi(h,<)][ansi(g,Friend System)][ansi(h,>)] [name(%q0)] is already in your deny list.)],[set(%#,stat`denyfriend:[xget(%#,stat`denyfriend)] %q0)][pemit(%#,[ansi(h,<)][ansi(g,Friend System)][ansi(h,>)] [name(%q0)] added to your friend denial list.)])])] &CMD`FRIEND_DENYLIST Friends System v1.0 <FS>=$+friend/denied:th [pemit(%#,[header([ansi(g,Friends Denied)])]%R[table([iter([xget(%#,stat`denyfriend)],[name(%i0)])],38,78,|)]%R[header()])] &CMD`FRIEND_LIST Friends System v1.0 <FS>=$+friends:th [pemit(%#,[header([ansi(g,Friends List)])]%R[align(25 12 25 10,Name,Status,Name,Status)]%R[table([iter([xget(%#,stat`friends)],[ljust([left([name(%i0)],25)],26)][if([hasflag(%i0,connected)],[ansi(hg,ONLINE)],[ansi(hr,OFFLINE)])],%b,|)],38,78,|)]%R[header()])] &CMD`FRIEND_NOTIFY Friends System v1.0 <FS>=$+friend/notify:th [if([match([xget(%#,stat`fnotify)],1)],[pemit(%#,[ansi(h,<)][ansi(g,Friend System)][ansi(h,>)] Friend connection notification turned off.)][set(%#,stat`fnotify:0)],[set(%#,stat`fnotify:1)][pemit(%#,[ansi(h,<)][ansi(g,Friend System)][ansi(h,>)] Friend connection notification turned on.)])] &CMD`FRIEND_UNDENY Friends System v1.0 <FS>=$+friend/undeny *:th [setq(0,[pmatch(%0)])][if([match([xget(%#,stat`denyfriend)],%q0)],[set(%#,stat`denyfriend:[remove([xget(%#,stat`denyfriend)],%q0)])][pemit(%#,[ansi(h,<)][ansi(g,Friend System)][ansi(h,>)] [name(%q0)] removed from your friend denial list.)],[pemit(%#,[ansi(h,<)][ansi(g,Friend System)][ansi(h,>)] That person is not in your deny list.)])]
Commands are pretty straightforward. If you need assistance, post here. Feel free to use or pick apart.
-
When I hear the words Connection Machine, I usually think of something more like