teeworlds 2.0.2 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -242,11 +242,13 @@ var Client = /** @class */ (function (_super) {
242
242
  var _this = this;
243
243
  if (ExtraMsg === void 0) { ExtraMsg = ""; }
244
244
  return new Promise(function (resolve, reject) {
245
- var latestBuf = Buffer.from([0x10 + (((16 << 4) & 0xf0) | ((_this.ack >> 8) & 0xf)), _this.ack & 0xff, 0x00, msg]);
246
- latestBuf = Buffer.concat([latestBuf, Buffer.from(ExtraMsg), _this.TKEN]); // move header (latestBuf), optional extraMsg & TKEN into 1 buffer
247
- _this.socket.send(latestBuf, 0, latestBuf.length, _this.port, _this.host, function (err, bytes) {
248
- resolve(bytes);
249
- });
245
+ if (_this.socket) {
246
+ var latestBuf = Buffer.from([0x10 + (((16 << 4) & 0xf0) | ((_this.ack >> 8) & 0xf)), _this.ack & 0xff, 0x00, msg]);
247
+ latestBuf = Buffer.concat([latestBuf, Buffer.from(ExtraMsg), _this.TKEN]); // move header (latestBuf), optional extraMsg & TKEN into 1 buffer
248
+ _this.socket.send(latestBuf, 0, latestBuf.length, _this.port, _this.host, function (err, bytes) {
249
+ resolve(bytes);
250
+ });
251
+ }
250
252
  setTimeout(function () { resolve("failed, rip"); }, 2000);
251
253
  /* after 2 seconds it was probably not able to send,
252
254
  so when sending a quit message the user doesnt
@@ -257,6 +259,8 @@ var Client = /** @class */ (function (_super) {
257
259
  Client.prototype.SendMsgEx = function (Msg, Flags) {
258
260
  if (this.State == -1)
259
261
  throw new Error("Client is not connected");
262
+ if (!this.socket)
263
+ return;
260
264
  var header = [];
261
265
  header[0] = ((Flags & 3) << 6) | ((Msg.size >> 4) & 0x3f);
262
266
  header[1] = (Msg.size & 0xf);
@@ -273,6 +277,8 @@ var Client = /** @class */ (function (_super) {
273
277
  var _this = this;
274
278
  if (this.State == -1)
275
279
  throw new Error("Client is not connected");
280
+ if (!this.socket)
281
+ return;
276
282
  var header = [];
277
283
  Msgs.forEach(function (Msg, index) {
278
284
  header[index] = new Array(2);
package/lib/client.ts CHANGED
@@ -242,12 +242,14 @@ class Client extends EventEmitter {
242
242
  }
243
243
  SendControlMsg(msg: number, ExtraMsg: string = "") {
244
244
  return new Promise((resolve, reject) => {
245
+ if (this.socket) {
246
+ var latestBuf = Buffer.from([0x10 + (((16 << 4) & 0xf0) | ((this.ack >> 8) & 0xf)), this.ack & 0xff, 0x00, msg])
247
+ latestBuf = Buffer.concat([latestBuf, Buffer.from(ExtraMsg), this.TKEN]) // move header (latestBuf), optional extraMsg & TKEN into 1 buffer
248
+ this.socket.send(latestBuf, 0, latestBuf.length, this.port, this.host, (err, bytes) => {
249
+ resolve(bytes)
250
+ })
245
251
 
246
- var latestBuf = Buffer.from([0x10 + (((16 << 4) & 0xf0) | ((this.ack >> 8) & 0xf)), this.ack & 0xff, 0x00, msg])
247
- latestBuf = Buffer.concat([latestBuf, Buffer.from(ExtraMsg), this.TKEN]) // move header (latestBuf), optional extraMsg & TKEN into 1 buffer
248
- this.socket.send(latestBuf, 0, latestBuf.length, this.port, this.host, (err, bytes) => {
249
- resolve(bytes)
250
- })
252
+ }
251
253
  setTimeout(() => { resolve("failed, rip") }, 2000)
252
254
  /* after 2 seconds it was probably not able to send,
253
255
  so when sending a quit message the user doesnt
@@ -258,6 +260,8 @@ class Client extends EventEmitter {
258
260
  SendMsgEx(Msg: MsgPacker, Flags: number) {
259
261
  if (this.State == -1)
260
262
  throw new Error("Client is not connected");
263
+ if (!this.socket)
264
+ return;
261
265
  var header = []
262
266
  header[0] = ((Flags & 3) << 6) | ((Msg.size >> 4) & 0x3f);
263
267
  header[1] = (Msg.size & 0xf);
@@ -274,6 +278,8 @@ class Client extends EventEmitter {
274
278
  SendMsgExWithChunks(Msgs: MsgPacker[], Flags: number) {
275
279
  if (this.State == -1)
276
280
  throw new Error("Client is not connected");
281
+ if (!this.socket)
282
+ return;
277
283
  var header: any[][] = [];
278
284
 
279
285
  Msgs.forEach((Msg: MsgPacker, index) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teeworlds",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "Library for (ingame) teeworlds bots.",
5
5
  "license": "MIT",
6
6
  "main": "index.js",