Skip to content
Snippets Groups Projects
Commit d8eb9f1f authored by Atanamo's avatar Atanamo
Browse files

Clean up and Readme

parent e2046133
No related branches found
No related tags found
No related merge requests found
The OpenShift `nodejs` cartridge documentation can be found at:
"IRC Gateway" is a simple chat server based on Node.js and Socket.io with an example web UI.
 
https://github.com/openshift/origin-server/tree/master/cartridges/openshift-origin-cartridge-nodejs/README.md
In general it is meant to be used for browser-based multiplayer web games with various game instances/servers/worlds/maps.
But in specific, the project targets the german browsergame "Stars, Gates & Realities" (http://sg-realities.de), also called SGR.*
For each game world a player can create and join multiple chat channels (chat rooms).
Each channel saves all sent messages persintantly - at least a maximum number.
By this, a player can read the channel history after joining. This allows groups of players to use own channels for time-displaced discussions in kind of a forum.
Additionally there is a special channel for each world, which is the in-game representation of a public IRC channel.
The list of players currently connected to this channel is hidden to each other. The players only communicate through an IRC bot.
Clients directly connected to the IRC channel do only see the bot and what he messages in role of a player in-game.
This way, on IRC there is only one bot for each game world. The bot represents all players in its world.
(Therefor the chat server and its bots are a kind of gateway between IRC and in-game chat.)
* Note, that for developing purposes game worlds might be called "galaxies" inside the project, due to the terminology of SGR.
node ./src_js/sample.js
pause
\ No newline at end of file
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Welcome to OpenShift</title>
<style>
html {
background: black;
}
body {
background: #333;
background: -webkit-linear-gradient(top, black, #666);
background: -o-linear-gradient(top, black, #666);
background: -moz-linear-gradient(top, black, #666);
background: linear-gradient(top, black, #666);
color: white;
font-family: "Helvetica Neue",Helvetica,"Liberation Sans",Arial,sans-serif;
width: 40em;
margin: 0 auto;
padding: 3em;
}
a {
color: white;
}
h1 {
text-transform: capitalize;
-moz-text-shadow: -1px -1px 0 black;
-webkit-text-shadow: 2px 2px 2px black;
text-shadow: -1px -1px 0 black;
box-shadow: 1px 2px 2px rgba(0, 0, 0, 0.5);
background: #CC0000;
width: 22.5em;
margin: 1em -2em;
padding: .3em 0 .3em 1.5em;
position: relative;
}
h1:before {
content: '';
width: 0;
height: 0;
border: .5em solid #91010B;
border-left-color: transparent;
border-bottom-color: transparent;
position: absolute;
bottom: -1em;
left: 0;
z-index: -1000;
}
h1:after {
content: '';
width: 0;
height: 0;
border: .5em solid #91010B;
border-right-color: transparent;
border-bottom-color: transparent;
position: absolute;
bottom: -1em;
right: 0;
z-index: -1000;
}
h2 {
margin: 2em 0 .5em;
border-bottom: 1px solid #999;
}
pre {
background: black;
padding: 1em 0 0;
-webkit-border-radius: 1em;
-moz-border-radius: 1em;
border-radius: 1em;
color: #9cf;
}
ul {
margin: 0;
padding: 0;
}
li {
list-style-type: none;
padding: .5em 0;
}
.brand {
display: block;
text-decoration: none;
}
.brand .brand-image {
float: left;
border: none;
}
.brand .brand-text {
float: left;
font-size: 24px;
line-height: 24px;
padding: 4px 0;
color: white;
text-transform: uppercase;
}
.brand:hover,
.brand:active {
text-decoration: underline;
}
.brand:before,
.brand:after {
content: ' ';
display: table;
}
.brand:after {
clear: both;
}
</style>
</head>
<body>
<a href="http://openshift.com" class="brand">
<img class="brand-image"
alt="OpenShift logo"
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAgCAYAAABU1PscAAAAAXNSR0IArs4c6QAAAAZiS0dEAAAAAAAA+UO7fwAAAAlwSFlzAAARHgAAER4B27UUrQAABUhJREFUWMPFWFlsVGUU/s5/70zbaSltA7RQpJ2lC9CFkQkWIgSJxkAhRA0JCYFq4hPG6JsoGKNCtPigxqhvGlPAuGIaE4igNaElbIW2yNL2tkOtTYGWCqWF2e79fCh7p1Bmpnge/3vuOef7z/nPJiTxMHS6pMRuu6YqFNTTAJYSyAU4GZB0AH2AGCANAfc5Qrba6T3HrmECScYLwCioSIcV2AjidQDZ45Q/LJRaWrLV03X89P8GwHB5XwG4DcDkGPWEBKimNrzN094efGQAzjm9GWHFr4R4LiHKgFaSL3r8zYcmHEBbkW+KFo7UEyhKsNeHlMgyV8eJo4kQpqId9ub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eeAuk9eBtRvkqUH0MoTsqA7nL429eFzeA3lyfQ08eaiNgCrjTYNozQ1S+WyUfQCosTLqZ+oiDUNwhggPujpZTuCMXGwUV6cJgKYnNIJffR3df2NLLZ5871puQrUR//pzpU7rOnAfJP53eDELrsoPpk4RIGRn5xqIBAAdBOCAoBjBjPJsJUdZSt9HSOGFrld5cn2M4KbwfkIUJzqYhQlYWdJ7YN2FrFQCY3nPsmk61AuSuRNYyUdaiRBk/7tViR37Zcir1JYC8WNshgjWWPfhq0dmzVx/5bhQAWnLKU1Md8gZHOsjxAgmD2GEKq4s6m1sxASQPu16HiBh53goqPg9ac0TEcwNQEOBlQAZEcMgC94dDZt2c7r8GMIH0H43ZRDC51RVCAAAAAElFTkSuQmCC">
<div class="brand-text"><strong>Open</strong>Shift</div>
</a>
<h1>
Welcome to OpenShift
</h1>
<p>
Place your application here
</p>
<p>
In order to commit to your new project, go to your projects git repo (created with the rhc app create command). Make your changes, then run:
</p>
<pre>
git commit -a -m 'Some commit message'
git push
</pre>
<p>
Then reload this page.
</p>
<h2>
What's next?
</h2>
<ul>
<li>
Why not visit us at <a href="http://www.openshift.com">http://www.openshift.com</a>, or
</li>
<li>
You could get help in the <a href="http://www.openshift.com/forums/openshift">OpenShift forums</a>, or
</li>
<li>
You're welcome to come chat with us in our IRC channel at #openshift on freenode.net
</li>
</ul>
</body>
</html>
#!/bin/env node
// OpenShift sample Node application
var express = require('express');
var fs = require('fs');
/**
* Define the sample application.
*/
var SampleApp = function() {
// Scope.
var self = this;
/* ================================================================ */
/* Helper functions. */
/* ================================================================ */
/**
* Set up server IP address and port # using env variables/defaults.
*/
self.setupVariables = function() {
// Set the environment variables we need.
self.ipaddress = process.env.OPENSHIFT_NODEJS_IP;
self.port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
if (typeof self.ipaddress === "undefined") {
// Log errors on OpenShift but continue w/ 127.0.0.1 - this
// allows us to run/test the app locally.
console.warn('No OPENSHIFT_NODEJS_IP var, using 127.0.0.1');
self.ipaddress = "127.0.0.1";
};
};
/**
* Populate the cache.
*/
self.populateCache = function() {
if (typeof self.zcache === "undefined") {
self.zcache = { 'index.html': '' };
}
// Local cache for static content.
self.zcache['index.html'] = fs.readFileSync('./index.html');
};
/**
* Retrieve entry (content) from cache.
* @param {string} key Key identifying content to retrieve from cache.
*/
self.cache_get = function(key) { return self.zcache[key]; };
/**
* terminator === the termination handler
* Terminate server on receipt of the specified signal.
* @param {string} sig Signal to terminate on.
*/
self.terminator = function(sig){
if (typeof sig === "string") {
console.log('%s: Received %s - terminating sample app ...',
Date(Date.now()), sig);
process.exit(1);
}
console.log('%s: Node server stopped.', Date(Date.now()) );
};
/**
* Setup termination handlers (for exit and a list of signals).
*/
self.setupTerminationHandlers = function(){
// Process on exit and signals.
process.on('exit', function() { self.terminator(); });
// Removed 'SIGPIPE' from the list - bugz 852598.
['SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGILL', 'SIGTRAP', 'SIGABRT',
'SIGBUS', 'SIGFPE', 'SIGUSR1', 'SIGSEGV', 'SIGUSR2', 'SIGTERM'
].forEach(function(element, index, array) {
process.on(element, function() { self.terminator(element); });
});
};
/* ================================================================ */
/* App server functions (main app logic here). */
/* ================================================================ */
/**
* Create the routing table entries + handlers for the application.
*/
self.createRoutes = function() {
self.routes = { };
// Routes for /health, /asciimo and /
self.routes['/health'] = function(req, res) {
res.send('1');
};
self.routes['/asciimo'] = function(req, res) {
var link = "http://i.imgur.com/kmbjB.png";
res.send("<html><body><img src='" + link + "'></body></html>");
};
self.routes['/'] = function(req, res) {
res.setHeader('Content-Type', 'text/html');
res.send(self.cache_get('index.html') );
};
};
/**
* Initialize the server (express) and create the routes and register
* the handlers.
*/
self.initializeServer = function() {
self.createRoutes();
self.app = express.createServer();
// Add handlers for the app (from the routes).
for (var r in self.routes) {
self.app.get(r, self.routes[r]);
}
};
/**
* Initializes the sample application.
*/
self.initialize = function() {
self.setupVariables();
self.populateCache();
self.setupTerminationHandlers();
// Create the express server and routes.
self.initializeServer();
};
/**
* Start the server (starts up the sample application).
*/
self.start = function() {
// Start the app on the specific interface (and port).
self.app.listen(self.port, self.ipaddress, function() {
console.log('%s: Node server started on %s:%d ...',
Date(Date.now() ), self.ipaddress, self.port);
});
};
}; /* Sample Application. */
/**
* main(): Main code.
*/
var zapp = new SampleApp();
zapp.initialize();
zapp.start();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment