Skip to content

Commit

Permalink
Update webclient to use native fcdb auth mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
zekoz committed Jul 25, 2019
1 parent ad9af79 commit d307cca
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 31 deletions.
45 changes: 23 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ THE FREECIV-WEB PROJECT
[![Code Quality: Javascript](https://img.shields.io/lgtm/grade/javascript/g/freeciv/freeciv-web.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/freeciv/freeciv-web/context:javascript)
[![Total Alerts](https://img.shields.io/lgtm/alerts/g/freeciv/freeciv-web.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/freeciv/freeciv-web/alerts)

Freeciv-web is an open-source turn-based strategy game. It can be played in any HTML5 capable web-browser and features in-depth game-play and a wide variety of game modes and options. Your goal is to build cities, collect resources, organize your government, and build an army, with the ultimate goal of creating the best civilization. You can play online against other players (multiplayer) or play by yourself against the computer. There is both a HTML5 2D version with isometric graphics and a 3D WebGL version of Freeciv-web.
Freeciv-web is an open-source turn-based strategy game. It can be played in any HTML5 capable web-browser and features in-depth game-play and a wide variety of game modes and options. Your goal is to build cities, collect resources, organize your government, and build an army, with the ultimate goal of creating the best civilization. You can play online against other players (multiplayer) or play by yourself against the computer. There is both a HTML5 2D version with isometric graphics and a 3D WebGL version of Freeciv-web.

Freeciv-web is free and open source software. The Freeciv C server is released under the GNU General Public License, while the Freeciv-web client is released
under the GNU Affero General Public License. See [License](LICENSE.txt) for the full license document.

Currently known servers based on Freeciv-web:
- [freecivweb.org](https://www.freecivweb.org)
- [freeciv.xyz](https://www.freeciv.xyz)
- [moving borders](https://fcw.movingborders.es) (Everything except longturn and real-Earth)

Freeciv WebGL 3D:
Expand All @@ -29,29 +29,29 @@ Freeciv-Web consists of these components:
* [Freeciv-web](freeciv-web) - a Java web application for the Freeciv-web client.
This application is a Java web application which make up the application
viewed in each user's web browser. The Metaserver is also a part of this module.
Implemented in Javascript, Java, JSP, HTML and CSS. Built with maven and runs
Implemented in Javascript, Java, JSP, HTML and CSS. Built with maven and runs
on Tomcat 8 and nginx.

* [Freeciv](freeciv) - the Freeciv C server, which is checked out from the official
Git repository, and patched to work with a WebSocket/JSON protocol. Implemented in C.

* [Freeciv-proxy](freeciv-proxy) - a WebSocket proxy which allows WebSocket clients in Freeciv-web
to send socket requests to Freeciv servers. WebSocket requests are sent from Javascript
in Freeciv-web to nginx, which then proxies the WebSocket messages to freeciv-proxy,
to send socket requests to Freeciv servers. WebSocket requests are sent from Javascript
in Freeciv-web to nginx, which then proxies the WebSocket messages to freeciv-proxy,
which finally sends Freeciv socket requests to the Freeciv servers. Implemented in Python.

* [Publite2](publite2) - a process launcher for Freeciv C servers, which manages
multiple Freeciv server processes and checks capacity through the Metaserver.
multiple Freeciv server processes and checks capacity through the Metaserver.
Implemented in Python.

* [pbem](pbem) is play-by-email support.
* [pbem](pbem) is play-by-email support.

* [freeciv-earth](freeciv-earth) is code to generate Freeciv savegames from a map captured from mapbox.

Freeciv WebGL
-------------
Freeciv WebGL is the 3D version, which uses the Three.js 3D engine. More info about the WebGL 3D version can be found for [developers](https://github.com/freeciv/freeciv-web/tree/develop/freeciv-web/src/main/webapp/javascript/webgl) and [3D artists](https://github.com/freeciv/freeciv-web/wiki/Contributing-Blender-models-for-Freeciv-WebGL).
Developer: Andreas Røsdal [@andreasrosdal](http://www.twitter.com/andreasrosdal)
Developer: Andreas Røsdal [@andreasrosdal](http://www.twitter.com/andreasrosdal)

Running Freeciv-web on your computer
------------------------------------
Expand Down Expand Up @@ -82,9 +82,9 @@ like dos2unix after saving them.

### Running Freeciv-web with Vagrant on VirtualBox

Freeciv-web can be setup using Vagrant on VirtualBox to quickly create a
Freeciv-web can be setup using Vagrant on VirtualBox to quickly create a
local developer image running Freeciv-web on latest Ubuntu on your host
operating system such as Windows, OSX or Linux.
operating system such as Windows, OSX or Linux.
This is the recommended way to build Freeciv-web on your computer.

1. Install VirtualBox: https://www.virtualbox.org/ - Install manually on Windows, and with the following command on Linux:
Expand All @@ -107,7 +107,7 @@ sudo apt-get install vagrant

4. Test Freeciv-web by pointing your browser to http://localhost if you run Windows or http://localhost:8080 if you run Linux or macOS.

To log in to your Vagrant server, run the command:
To log in to your Vagrant server, run the command:
```bash
vagrant ssh
```
Expand All @@ -120,9 +120,9 @@ and 3 Gb of harddisk space.

Install this software if you are not running Freeciv-web with Vagrant:

- Tomcat 8 - https://tomcat.apache.org/
- Tomcat 8 - https://tomcat.apache.org/

- Java 8 JDK - http://www.oracle.com/technetwork/java/javase/downloads/
- Java 8 JDK - http://www.oracle.com/technetwork/java/javase/downloads/

- Python 3.6 - http://www.python.org/

Expand Down Expand Up @@ -157,9 +157,9 @@ Install this software if you are not running Freeciv-web with Vagrant:
When in a [tested system](scripts/install/systems),
you may run `scripts/install/install.sh` and it will fetch and configure what's needed.

Start and stop Freeciv-web with the following commands:
start-freeciv-web.sh
stop-freeciv-web.sh
Start and stop Freeciv-web with the following commands:
start-freeciv-web.sh
stop-freeciv-web.sh
status-freeciv-web.sh

All software components in Freeciv-web will log to the /logs sub-directory of the Freeciv-web installation.
Expand All @@ -184,7 +184,7 @@ http://localhost/
Enjoy. The overall dockerfile and required changes to scripts needs some further improvements.


Freeciv-Web continuous integration on Travis CI
Freeciv-Web continuous integration on Travis CI
-----------------------------------------------
Freeciv-Web is built on Travis CI on every commit. This is the current build status: [![Build Status](https://api.travis-ci.org/freeciv/freeciv-web.png)](https://travis-ci.org/freeciv/freeciv-web)

Expand All @@ -193,17 +193,18 @@ Freeciv-web has CasperJS tests which are run by Travis CI on every commit, and b
Developers interested in Freeciv-web
------------------------------------
If you want to contibute to Freeciv-web, see the [issues](https://github.com/freeciv/freeciv-web/issues) on GibHub and the [TODO file](TODO) for
some tasks you can work on. Pull requests on Github is welcome!
If you want to contibute to Freeciv-web, see the [issues](https://github.com/freeciv/freeciv-web/issues) on GibHub and the [TODO file](TODO) for
some tasks you can work on. Pull requests on Github is welcome!
Contributors to Freeciv-web
---------------------------
Andreas Røsdal [@andreasrosdal](https://github.com/andreasrosdal)
Zoltan Zarkov [@zekoz](https://github.com/zekoz)
Marko Lindqvist [@cazfi](https://github.com/cazfi)
Sveinung Kvilhaugsvik [@kvilhaugsvik](https://github.com/kvilhaugsvik)
Gerik Bonaert [@adaxi](https://github.com/adaxi)
Lmoureaux [@lmoureaux](https://github.com/lmoureaux)
Máximo Castañeda [@lonemadmax](https://github.com/lonemadmax)
and the [Freeciv.org project](http://freeciv.wikia.com/wiki/People)!
Andreas Røsdal [@andreasrosdal](https://github.com/andreasrosdal)
and the [Freeciv.org project](http://freeciv.wikia.com/wiki/People)!
4 changes: 2 additions & 2 deletions freeciv-web/src/main/webapp/javascript/clinet.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function check_websocket_ready()
sha_password = encodeURIComponent(shaObj.getHash("HEX"));
}

if (is_longturn() && google_user_token == null) {
if (is_longturn() && fcw_token == null) {
swal("Login failed.");
return;
}
Expand All @@ -160,7 +160,7 @@ function check_websocket_ready()
"capability": freeciv_version, "version_label": "-dev",
"major_version" : 2, "minor_version" : 5, "patch_version" : 99,
"port": civserverport,
"password": google_user_token == null ? sha_password : google_user_token};
"password": fcw_token == null ? sha_password : fcw_token};
ws.send(JSON.stringify(login_message));

/* Leaving the page without saving can now be an issue. */
Expand Down
8 changes: 8 additions & 0 deletions freeciv-web/src/main/webapp/javascript/packhand.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,14 @@ function update_client_state(value)

function handle_authentication_req(packet)
{
if (is_longturn()) {
var login = {
"pid" : packet_authentication_reply,
"password" : fcw_token,
};
send_request(JSON.stringify(login));
return;
}
show_auth_dialog(packet);
}

Expand Down
14 changes: 7 additions & 7 deletions freeciv-web/src/main/webapp/javascript/pregame.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var antialiasing_setting = true;
var update_player_info_pregame_queued = false;
var password_reset_count = 0;
var google_user_token = null;
var fcw_token = null;

/****************************************************************************
...
Expand Down Expand Up @@ -1701,15 +1702,14 @@ function google_signin_on_success(googleUser)
xhr.open('POST', '/token_signin');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function() {
if (xhr.responseText == "OK") {
google_user_token = id_token;
simpleStorage.set("username", username);
$("#dialog").dialog('close');
} else if (xhr.responseText == "Email not verified") {
swal("Login failed. E-mail not verified.");
} else {
if (xhr.status != 200) {
swal("Login failed.");
return;
}
fcw_token = xhr.responseText;
google_user_token = id_token;
simpleStorage.set("username", username);
$("#dialog").dialog('close');
};
xhr.send('idtoken=' + id_token + "&username=" + username);

Expand Down

0 comments on commit d307cca

Please sign in to comment.