Skip to content

Commit

Permalink
Add --all-recipients and --allow-all to receive subcommand.
Browse files Browse the repository at this point in the history
  • Loading branch information
brannondorsey committed Oct 7, 2018
1 parent 1b06bde commit f3883a7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ function parseArgs(): any {
help: 'Receive messages with invalid signatures.',
})

receive.addArgument(['--all-recipients', '-g'], {
action: 'storeTrue',
dest: 'allRecipients',
help: 'Receive messages to all callsigns and chat rooms.',
})

receive.addArgument(['--allow-all', '-a'], {
action: 'storeTrue',
dest: 'allowAll',
help: 'Receive all messages, independent of signatures and destinations.',
})

receive.addArgument(['--raw', '-r'], {
action: 'storeTrue',
dest: 'raw',
Expand Down
12 changes: 7 additions & 5 deletions src/subcommands/receive.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Config } from '../config'
import { Keystore } from '../Keystore'
import { Messenger, MessageEvent, Verification } from '../Messenger'
import { stationToCallsignSSID } from '../utils'
import { stationToCallsignSSID, callsignSSIDToStation } from '../utils'
import { Station } from '../Packet'

function printVerbose(message: MessageEvent, raw: boolean): void {
let msg = `[verbose] received a packet with `
Expand Down Expand Up @@ -38,10 +39,11 @@ export async function main(args: any, conf: Config, ks: Keystore): Promise<numbe
})

messenger.on('message', (message: MessageEvent) => {
if (args.verbose) printVerbose(message, args.raw)
if (message.to.callsign === 'CQ' ||
(message.to.callsign === conf.callsign &&
message.to.ssid === conf.ssid)) {
const to: Station = callsignSSIDToStation(args.to)
if (args.verbose) printVerbose(message, args.raw)
if (args.allowAll) printPacket(message, args.raw)
else if (args.allRecipients ||
(message.to.callsign === to.callsign && message.to.ssid == to.ssid)) {
if (message.verification === Verification.Valid) {
printPacket(message, args.raw)
} else if (args.allowUnsigned && message.verification === Verification.NotSigned) {
Expand Down

0 comments on commit f3883a7

Please sign in to comment.