123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- class Output {
- toServer(message) {
- //process.stdout.write(message);
- console.log(message);
- }
- toServerError(message, error) {
- //process.stderr.write(message);
- console.error(message, error, error.stack);
- }
- toMobile(mobileId, message, source) {
- if(!Array.isArray(mobileId)) {
- mobileId = [mobileId];
- }
- for(var mobileIndex in mobileId) {
- var mobile = session.mobiles[mobileId[mobileIndex]];
- if(mobile == null || mobile == {}) {
- continue;
- }
- var messages = message.split("\r\n");
- for(var messageIndex in messages) {
- mobile.mud_sendMessage(source, messages[messageIndex]);
- }
- }
- }
- toRoom(roomName, message, source) {
- var room = session.rooms[roomName];
- if(room == null || room == {}) {
- return;
- }
- for(var mobileIndex in room.mobiles) {
- var mobileId = room.mobiles[mobileIndex];
- if(this.isIncludedInSources(mobileId, source)) {
- continue;
- }
- this.toMobile(mobileId, message, source);
- }
- }
- isIncludedInSources(mobileId, source) {
- var sources = [];
- if(Array.isArray(source)) {
- sources = source;
- } else {
- sources = [source];
- }
- for(var sourceIndex in sources) {
- var sourceObj = sources[sourceIndex];
- if(sourceObj != null && sourceObj.id == mobileId) {
- return true;
- }
- }
- return false;
- }
- matchesId(sources, id) {
- for(var i = 0; i < sources.length; i++) {
- if(sources[i].id == id) {
- return sources[i];
- }
- }
- return sources[0];
- }
- worldToMobiles(message, source) {
- this.toMobile(session.mobiles, message, source);
- }
- toBuildersError(message, error) {
- for(var mobileId in session.mobiles) {
- var mobile = session.mobiles[mobileId];
- if(mobile == null || mobile == {}) {
- continue;
- }
- if(world.mud_mobileHasRole(mobile.id, "builder")) {
- this.toMobile(mobile.id, message);
- this.toMobile(mobile.id, error.stack);
- }
- }
- }
- }
- module.exports = new Output();
|