~lastrosade/MNC

eef7222ac051e14bbaf075994f9ed6cc923b72e9 — jeremy.shields 5 years ago a9fb479
Readability, Messages Max Length, Changed License
5 files changed, 26 insertions(+), 27 deletions(-)

M LICENSE
M README.md
M index.js
M package.json
M settings.json.template
M LICENSE => LICENSE +7 -17
@@ 1,21 1,11 @@
MIT License
Copyright 2018 Jeremy Lee Shields <jeremy.shields@orange.fr>

Copyright (c) 2018 jeremy.shields
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file

M README.md => README.md +4 -6
@@ 11,7 11,7 @@ The only clients you need are either netcat (recommended) or telnet
```shell
git clone https://gitgud.io/jeremy.shields/MNC.git
npm i
node index.js -h
node index.js
```

### Prerequisites


@@ 28,6 28,8 @@ npm and node

```-2 port``` Specify the writing server port

```-m length``` Specify the maximum message length

then netcat or telnet to the reading and writing server

eg: ```netcat localhost 44033```


@@ 40,17 42,13 @@ eg: ```netcat localhost 44033```
* [CRC](https://www.npmjs.com/package/crc)
* [net](https://www.npmjs.com/package/net)

## Versioning

Whatever

## Author

[**Jeremy Lee Shields**](http://jeremylee.sh/)

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
This project is licensed under the BSD 3-Clause License - see the [LICENSE](LICENSE) file for details

## Issues


M index.js => index.js +10 -3
@@ 22,6 22,7 @@ program
    .option('-h, --host  [Host]', 'Host')
    .option('-1, --port1 [Port]', 'Reading server port')
    .option('-2, --port2 [Port]', 'Writing server port')
    .option('-m, --maxlen [Length]', 'Maximum messages length')
    .option('-d, --dev'         , 'Dev mode') // Dev mode prints stuff
    .parse(process.argv);



@@ 29,6 30,7 @@ program
const host  = program.host  || settings.host  || "localhost";
const port1 = program.port1 || settings.port1 || 44033;
const port2 = program.port2 || settings.port2 || 44044;
const max_len = program.maxlen || settings.maxlen || 256;
const dev = program.dev || settings.dev;

// Salt to use when hashing IPs


@@ 46,7 48,7 @@ var writers = [];
// Reading server
var read = net.createServer((reader) => {
    readers.push(reader);
    reader.name = crc32(reader.remoteAddress+salt).toString(16) + "::" + reader.remotePort;
    reader.name = crc32(reader.remoteAddress+salt).toString(16) + " :: " + reader.remotePort;

    reader.write("Welcome ! this is a tcp chat reader,\r\n You can write at adress: "+host+", port "+port2+"\r\n\r\n");



@@ 66,7 68,7 @@ read.listen(port1, host);
// Writing Server
var write = net.createServer((writer) => {
    writers.push(writer);
    writer.name = crc32(writer.remoteAddress+salt).toString(16) + "::" + writer.remotePort;
    writer.name = crc32(writer.remoteAddress+salt).toString(16) + " :: " + writer.remotePort;
    broadcast(readers, writer.name + " joined as writer\n", writer);

    writer.write(


@@ 81,6 83,11 @@ var write = net.createServer((writer) => {

    writer.on('data', function (data) {
        data = data.toString().trim(); // Since data is an object call toString before trimming
        if (data.length > max_len) {
            writer.write("<"+data.substring(max_len, data.length)+"> This Was Trimmed out because your message was too long!\r\nThe maximum length is "+max_len+"\r\n");
            data = data.substring(0, max_len);
        }


        // Get commands
        var s1 = data.split(' ')[0], s2 = data.split(' ')[1];


@@ 88,7 95,7 @@ var write = net.createServer((writer) => {
        // Rename command
        if (s1 === '!rename' || s1 === '!nick' || s1 === '!n') { // Check if commands are not empty or undefined
            if (s2 != '' && s2 != undefined) {
                s2 = crc32(writer.remoteAddress+salt).toString(16) + "::" + truncate(s2.trim(), 10);
                s2 = crc32(writer.remoteAddress+salt).toString(16) + " :: " + truncate(s2.trim(), 10);
                broadcast(readers, '@Notice, \''+writer.name+ '\' Changed nick to \''+s2+'\'\r\n');
                writer.write("Nick changed\r\n");
                writer.name = s2;

M package.json => package.json +1 -1
@@ 1,6 1,6 @@
{
  "name": "MNC",
  "version": "1.0.0",
  "version": "1.2.0",
  "description": "",
  "main": "index.js",
  "scripts": {

M settings.json.template => settings.json.template +4 -0
@@ 8,4 8,8 @@
    "//": "Dev mode",

        "dev": "false"

    "//": "Chat settings",

        "maxlen": 256
}
\ No newline at end of file