Skip to content

Commit efc24cb

Browse files
author
Myonara
committed
0.0.6: implmented sound support on GMCP.
1 parent b571db5 commit efc24cb

5 files changed

Lines changed: 58 additions & 12 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
# webmud3 V0.0.5 !!!
1+
# webmud3 V0.0.6 !!!
22
Webmud3: third generation of the UNItopia Webmud as open source project.
33

44
In this early stages (Versions < 0.1.0) it's not for production.
55
Version 0.0.2 delivers a configurable list of muds in frontend/config/config.development, so that the development mode can be used as local browser-mudclient to multiple muds.
66
Version 0.0.3 added ANSI colour support
77
Version 0.0.4 fixed an ANSI colour issue and renamed frontend dir to backend.
88
Version 0.0.5 implmented telnet_neg: echo,terminaltype and naws. started with GMCP support.
9+
Version 0.0.6 implemented sound on top of GMCP, working with UNItopia so far.
910

1011
## Installation in the Development environment
1112
### One time prerequisites:

UI/src/app/mudclient/mudclient.component.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ export class MudclientComponent implements OnInit,OnDestroy {
6767
switch (musi.signal) {
6868
case 'NOECHO-START': other.inpType = 'password'; break;
6969
case 'NOECHO-END': other.inpType = 'text'; break;
70+
case 'Sound.Play.Once':
71+
console.log("Play: ",musi.playSoundFile);
72+
let audio = new Audio();
73+
audio.src = musi.playSoundFile;
74+
audio.load();
75+
audio.play();
76+
break;
7077
}
7178
});
7279
other.obs_data = other.socketService.mudReceiveData(_id).subscribe(outline => {

UI/src/app/shared/mud-signals.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export class MudSignals {
22
signal : string;
33
id : string;
4+
playSoundFile?: string;
45
}

UI/src/app/shared/socket.service.ts

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,15 @@ export class SocketService {
243243
return observable;
244244
}
245245

246+
public sendGMCP(id:string,mod:string,msg:string,data:any) {
247+
if (typeof this.mudConnections[id] === 'undefined') {
248+
console.log('failed[GMCP_Send_packet].mudconn='+id);
249+
return;
250+
}
251+
console.log('GMCP-send:',mod,msg,data);
252+
this.socket.emit('mud-gmcp-outgoing',id,mod,msg,data);
253+
}
254+
246255
public mudReceiveData(_id: string) : Observable<string> {
247256
let other = this;
248257
let observable = new Observable<string>(observer => {
@@ -251,16 +260,6 @@ export class SocketService {
251260
return;
252261
}
253262
other.logger.add('mudReceiveData starting!',false);
254-
other.socket.on('mud-gmcp-incoming',function(id,mod,msg,data){
255-
if (typeof other.mudConnections[id] === 'undefined') {
256-
console.log('failed[mud-gmcp-incoming].mudconn='+id);
257-
return;
258-
}
259-
if (_id !== id) {
260-
return;
261-
}
262-
console.log('GMCP:',mod,msg,data);
263-
});
264263
other.socket.on('mud-get-naws', function(id,cb) {
265264
if (typeof other.mudConnections[id] === 'undefined') {
266265
console.log('failed[mud-get-naws].mudconn='+id);
@@ -308,6 +307,43 @@ export class SocketService {
308307
}
309308
observer.next(musi);
310309
})
310+
other.socket.on('mud-gmcp-incoming',function(id,mod,msg,data){
311+
if (typeof other.mudConnections[id] === 'undefined') {
312+
console.log('failed[mud-gmcp-incoming].mudconn='+id);
313+
return;
314+
}
315+
if (_id !== id) {
316+
return;
317+
}
318+
switch (mod.toLowerCase().trim()) {
319+
case 'core':
320+
switch (msg.toLowerCase().trim()) {
321+
case 'hello':
322+
other.mudConnections[_id]['gmcp-mudname'] = data.name;
323+
other.sendGMCP(_id,'Core','Hello',{'client':'Webmud3a','version':'0.0.6'});
324+
other.sendGMCP(_id,'Core','Supports.Set',['Sound 1']);
325+
break;
326+
}
327+
break;
328+
case 'sound':
329+
switch (msg.toLowerCase().trim()) {
330+
case 'url':
331+
other.mudConnections[_id]['sound-url'] = data.url;
332+
break;
333+
case 'event':
334+
let soundSignal : MudSignals = {
335+
signal: 'Sound.Play.Once',
336+
id: data.file,
337+
playSoundFile: other.mudConnections[_id]['sound-url']+'/'+data.file,
338+
}
339+
observer.next(soundSignal);
340+
break;
341+
}
342+
break;
343+
default:
344+
}
345+
console.log('GMCP:',mod,msg,data);
346+
});
311347
});
312348
return observable;
313349
}

backend/server.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ io.on('connection', (socket) => {
154154
mudSocket.write(inpline.toString('utf8')+"\r");
155155
}
156156
});
157-
socket.on('mud.gmcp-outgoing', (id,mod,msg,data) => {
157+
socket.on('mud-gmcp-outgoing', (id,mod,msg,data) => {
158158
if (typeof id !== 'string' || typeof MudConnections[id] === 'undefined') {
159159
io.emit("mud-error","Connection-id unknown");
160160
return;
@@ -165,6 +165,7 @@ io.on('connection', (socket) => {
165165
let b1 = new Buffer(mod+'.'+msg+' ');
166166
let b2 = new Buffer(jsdata);
167167
let buf = Buffer.concat([b1,b2],b1.length+b2.length);
168+
console.log(mod,msg,data);
168169
mudSocket.writeSub(201 /*TELOPT_GMCP*/, buf);
169170
});
170171

0 commit comments

Comments
 (0)