@superwhiskers/

undertale-textchat-thing

Express

No description

fork
loading
Files
  • index.js
  • views
  • package-lock.json
  • package.json

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.006704933448650419","path":"index.js","file":{"path":"index.js","content":{"asEncoding":{"base64":"Y29uc3QgYXBwID0gcmVxdWlyZSgnZXhwcmVzcycpKCkKY29uc3QgZGVidWdtb2QgPSByZXF1aXJlKCdkZWJ1ZycpCmNvbnN0IGRlYnVnID0gZGVidWdtb2QoJ3NlcnZlcicpCmNvbnN0IHNlcnZlciA9IHJlcXVpcmUoJ2h0dHAnKS5jcmVhdGVTZXJ2ZXIoYXBwKQpjb25zdCBpbyA9IHJlcXVpcmUoJ3NvY2tldC5pbycpKHNlcnZlcikKY29uc3Qgc2hhanMgPSByZXF1aXJlKCdzaGEuanMnKQoKbGV0IGNsaWVudGRhdGEgPSB7fQoKYXBwLmdldCgnLycsIChyZXEsIHJlcykgPT4gewoKCXJlcy5zZW5kRmlsZShfX2Rpcm5hbWUgKyAiL3ZpZXdzL2luZGV4Lmh0bWwiKQogIGRlYnVnKCdzZW50IHdlYnBhZ2UnKSAgCgp9KQoKaW8ub24oJ2Nvbm5lY3Rpb24nLCBzb2NrZXQgPT4gewoKICBkZWJ1Zygnc29tZW9uZSBoYXMgY29ubmVjdGVkIHRvIHRoZSBzb2NrZXQnKQogIHZhciBzaWQgPSBzb2NrZXQuaWQKCiAgZm9yIChpZCBpbiBjbGllbnRkYXRhKSB7CgogICAgaWYgKGNsaWVudGRhdGFbaWRdID09PSB1bmRlZmluZWQpIHsKCiAgICAgIGNvbnRpbnVlCgogICAgfQoKICAgIHNvY2tldC5lbWl0KCd0ZXh0dXBkYXRlJywgSlNPTi5zdHJpbmdpZnkoewogICAgICAndGV4dCc6IGNsaWVudGRhdGFbaWRdLmxhc3R0ZXh0LAogICAgICAnaWQnOiBzaGFqcygnc2hhMjU2JykudXBkYXRlKGlkKS5kaWdlc3QoJ2hleCcpCiAgICB9KSkK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pbmdpZnkoewogICAgICAnaWQnOiBzaGFqcygnc2hhMjU2JykudXBkYXRlKHNpZCkuZGlnZXN0KCdoZXgnKQogICAgfSkpCgogIH0pCgp9KQoKc2VydmVyLmxpc3RlbigzMDAwKQ=="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const app = require('express')()
const debugmod = require('debug')
const debug = debugmod('server')
const server = require('http').createServer(app)
const io = require('socket.io')(server)
const shajs = require('sha.js')

let clientdata = {}

app.get('/', (req, res) => {

	res.sendFile(__dirname + "/views/index.html")
  debug('sent webpage')  

})

io.on('connection', socket => {

  debug('someone has connected to the socket')
  var sid = socket.id

  for (id in clientdata) {

    if (clientdata[id] === undefined) {

      continue

    }

    socket.emit('textupdate', JSON.stringify({
      'text': clientdata[id].lasttext,
      'id': shajs('sha256').update(id).digest('hex')
    }))

  }

  socket.on('textupdate', sdata => {

    data = JSON.parse(sdata)
    var time = Date.now()

    if (clientdata[socket.id] !== undefined) {

      if (clientdata[socket.id].lasttext === data['text']) {

        return

      }

      clientdata[socket.id].lastcount = time
      clientdata[socket.id].lasttext = data['text']

    } else {

      clientdata[socket.id] = {
        lastcount: time,
        lasttext: data['text'],
      }

    }

    debug('client %s changed their message to "%s"', socket.id, data['text'])
    data['id'] = shajs('sha256').update(socket.id).digest('hex')
    socket.broadcast.emit('textupdate', JSON.stringify(data))

  })

  socket.on('disconnect', () => {

    debug('someone has disconnected from the socket')
    clientdata[sid] = undefined
    io.emit('disconnected', JSON.stringify({
      'id': shajs('sha256').update(sid).digest('hex')
    }))

  })

})

server.listen(3000)