-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added collision detection, events, and a new map area.
- Loading branch information
Showing
34 changed files
with
2,971 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
Javascript Game tutorial. | ||
|
||
I got the idea from That Guy (http://that-guy.net/). | ||
I got the idea from Niels Groot Obbink (http://that-guy.net/). | ||
|
||
This version is slightly modified from the tutorial. | ||
The idea is to use HTML 5 goodness! | ||
The idea is to use HTML 5 goodness! There are some extra unused files I was just messing around with. | ||
|
||
The game currently doesn't do much. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Copyright 2010 Micheil Smith. | ||
|
||
All rights reserved. | ||
|
||
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: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
# node-websocket-server # | ||
|
||
This is a server for the WebSocket Protocol. It currently to works | ||
with both [draft75](http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-75) and [draft76](http://www.whatwg.org/specs/web-socket-protocol/) of the protocol specification. | ||
|
||
## Compatibility ## | ||
|
||
This module is known to work with Node.js v0.1.98. May also work on Node.js greater than v0.1.94, dependent on protocol version being used. | ||
|
||
It has been reported that this module experiences some issues on solaris and ubuntu systems, so far these issues are unresolved, but seem to be related to the core of Node.js | ||
|
||
## Synopsis ## | ||
|
||
An example of a simple server that will echo the messages received back out can be found in `examples/echo-server.js`, coupled with a websocket client like the `examples/client.html`, and you have a working websocket client/server. | ||
|
||
## Server ## | ||
|
||
The server acts like a normal http server in many respects, and exposes much of node's http.Server events and | ||
methods. However, there are a few differences, and things that haven't yet been implemented. | ||
|
||
`ws.creareServer()` returns an instance of `ws.Server`, which acts like `http.Server`. However, not all methods | ||
and events that act on `http.Server` will act on `ws.Server`. Your application can handle normal http requests by listening for the "request" event. | ||
|
||
`ws.createServer()` and `ws.Server()` takes an options object as its only parameter. The options object has a these | ||
defaults: | ||
|
||
{ debug: false, // Boolean: Show debug information. | ||
, version: "auto" // String: Value must be either: draft75, draft76, auto | ||
, origin: "*" // String, Array: A match for a valid connection origin | ||
, subprotocol: null // String, Array: A match for a valid connection subprotocol. | ||
} | ||
|
||
After a websocket client connects to the server, the server will emit the `'connection'` event, with the `ws/connection` | ||
instance for the connection. This means that the connection has undertaken the necessary websocket handshaking and | ||
is now ready to send and receive data. | ||
|
||
**NOTE:** Currently the origin and subprotocols are not strictly checked, this will be added in future versions. | ||
|
||
### server.listen(port, host) ### | ||
|
||
The same as the `http.Server` listen method. | ||
|
||
### server.send(client_id, message) ### | ||
|
||
Sends `message` to the client with `id` of `client_id`. | ||
|
||
### server.broadcast(message) ### | ||
|
||
Sends `message` to all connected clients. | ||
|
||
### server.close() ### | ||
|
||
The same as the `http.Server` close method. | ||
|
||
### Event: listening ### | ||
|
||
`function () { }` | ||
|
||
Emits when the server is ready to start accepting clients, after `listen` has been called. | ||
|
||
### Event: connection ### | ||
|
||
`function (connection) { }` | ||
|
||
Emits when a websocket client connects to the server. The `connection` is an instance of `ws/connection`. | ||
|
||
### Event: request ### | ||
|
||
`function (request, response) { }` | ||
|
||
Emits when a client connects using standard HTTP to the server. | ||
This is the same as the `http.Server` `request` event. | ||
Use this to handle normal http connections that won't upgrade to WebSocket. | ||
|
||
### Event: stream ### | ||
|
||
`function (stream) { }` | ||
|
||
The same as the `http.Server` `stream` event. | ||
|
||
### Event: shutdown ### | ||
|
||
`function (errno) { }` | ||
|
||
Emits when the server is closed. Proxied from `http.Server` | ||
|
||
### Event: close ### | ||
|
||
`function(connection) { }` | ||
|
||
Emits when a websocket client's connection closes. The `connection` is an instance of `ws/connection`. | ||
|
||
## ws/connection ## | ||
|
||
This is an instance of a client connecting to the `ws.Server`, this is similar to the `req` on a `http.Server`. | ||
|
||
### connecting.getVersion() ### | ||
|
||
Returns the websocket specification version that the connection is using. | ||
|
||
### connection.write(data) ### | ||
|
||
Publishes a message to the client. | ||
|
||
### connection.close() ### | ||
|
||
Closes the client's connection. | ||
|
||
### connection.reject(reason) ### | ||
|
||
Rejects a client's connection. `reason` is only used when the server is in debug mode. | ||
|
||
### connection.handshake() ### | ||
|
||
This carries out handshaking with a client, this method is semi-private. | ||
|
||
### Event: stateChange ### | ||
|
||
`function (state, previous_state) { }` | ||
|
||
Each time the connection's status changes this is emitted, the state codes are: | ||
|
||
0. unknown | ||
1. opening | ||
2. waiting | ||
3. handshaking | ||
4, connected | ||
5. closed | ||
A state of `2` should never be reached, if it is, please do let me know. | ||
|
||
### Event: message ### | ||
|
||
`function (message) { }` | ||
|
||
Emits when a client sends a message to the server. | ||
|
||
### Event: close ### | ||
|
||
`function () { }` | ||
|
||
Emits when a connection is closes. | ||
|
||
### Event: rejected ### | ||
|
||
`function () { }` | ||
|
||
Emits when a connection is rejected by the server, usually for a bad handshake or version mismatch. This event is immediately followed by the `close` event | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
require 'rake' | ||
require 'rubygems' | ||
require 'json' | ||
|
||
puts "---" | ||
|
||
|
||
@version = `git describe`.match("v([0-9]+\.[0-9]+.\[0-9]+).*")[1] | ||
|
||
def to_node_json(obj) | ||
obj = obj.to_json | ||
# reformat it a bit | ||
obj.gsub!(/\"\}\]|\[\{|\}\,|\:\{|\:\[[^\{]|\{\"|\,\"|\:\{\"|\"\:|\"\}$/) {|s| | ||
case s | ||
when ",\""; "\n, \"" | ||
when "{\""; "{ \"" | ||
when ":{"; ":\n {" | ||
when ":["; ": [\n" | ||
when "},"; "}\n, " | ||
when "[{"; "[{ " | ||
when "\"}]"; "\" }]" | ||
when "\":"; "\": " | ||
when "\"}"; "\"\n}" | ||
else; s | ||
end | ||
} | ||
# finally clean up arrays. | ||
obj.gsub!(/(.+\[.+)\n\,/, '\1,').gsub(/\}$/, "\n}") | ||
end | ||
|
||
desc "Release a new version to various places." | ||
task :release => ['write:pkgspec', 'npm:publish'] do | ||
puts "Released!" | ||
puts "" | ||
end | ||
|
||
namespace :write do | ||
desc "Write the package.json file" | ||
task :pkgspec do | ||
package = { | ||
:name => "websocket-server", | ||
:version => @version, | ||
:author => "Micheil Smith <micheil@brandedcode.com>", | ||
:description => "A WebSocket Server for node.js, 90-100% spec compatible.", | ||
:main => "./lib/ws", | ||
:engines => { :node => ">=0.1.98-0" }, | ||
:licenses => [{ :type => "MIT", :url => "./LICENSE.md" }], | ||
:repository => { | ||
:type => "git", | ||
:url => "http://github.com/miksago/node-websocket-server.git" | ||
}, | ||
:bugs => { | ||
:web => "http://github.com/miksago/node-websocket-server/issues" | ||
} | ||
} | ||
|
||
puts "Making package.json" | ||
f = File.new("package.json", "w+") | ||
f.write(to_node_json(package)) | ||
f.close | ||
puts "-> Done" | ||
end | ||
end | ||
|
||
namespace :npm do | ||
desc "Publish to NPM" | ||
task :publish do | ||
puts "Publishing to NPM" | ||
system("npm publish #{`pwd`}") | ||
system("npm tag websocket-server #{@version} latest") | ||
puts "-> Done" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## NWS TODO ## | ||
|
||
* nothing | ||
|
||
## NWS Done ## | ||
|
||
* change `server` constructor to have externalServer as option, not argument | ||
* add `connection._req.headers` -> `connection.headers` | ||
* abstract `connection.storage` to use a standard API & events | ||
* add `manager.map` should have similar api to Array.map |
Oops, something went wrong.