This file contains hidden or 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
| func main() { | |
| r := mux.NewRouter() | |
| r.HandleFunc("/ws", remoteHandler) | |
| r.PathPrefix("/").Handler(http.FileServer(http.Dir("./public/"))) | |
| http.ListenAndServe(":3000", r) | |
| } |
This file contains hidden or 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
| func remoteHandler(res http.ResponseWriter, req *http.Request) { | |
| var err error | |
| //when someone requires a ws connection we create a new player and store a | |
| // pointer to the connection inside player.Socket | |
| ws, _ := websocket.Upgrade(res, req, nil, 1024, 1024) | |
| log.Printf("got websocket conn from %v\n", ws.RemoteAddr()) | |
| player := new(Player) | |
| player.Id = uuid.New() | |
| player.Socket = ws |
This file contains hidden or 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
| func (p *Player) position(new bool) Message { | |
| return Message{X: p.X, Y: p.Y, Id: p.Id, New: new, Online: true} | |
| } | |
| var Players = make([]*Player, 0) |
This file contains hidden or 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
| type Message struct { | |
| Y int // current Y position | |
| X int // as above | |
| Id string // the id of the player that sent the message | |
| New bool // true if this player just connected so we know when to | |
| // spawn a new sprite on the screens of the other players. for all subsequent | |
| // messages it's false | |
| Online bool // true if the player is no longer connected so the frontend | |
| // will remove it's sprite | |
| } |
This file contains hidden or 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
| package main | |
| import ( | |
| "code.google.com/p/go-uuid/uuid" | |
| "github.com/gorilla/mux" | |
| "github.com/gorilla/websocket" | |
| "log" | |
| "net/http" | |
| ) |
This file contains hidden or 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
| { | |
| "_id" : ObjectId("52fa44d6a0dfdb9c210254d4"), | |
| "created" : ISODate("2014-02-11T15:42:14.953Z"), | |
| "res" : { | |
| "headers" : { | |
| "content-length" : "22", | |
| "content-type" : "text/html; charset=utf-8", | |
| "x-powered-by" : "Express" | |
| }, | |
| "body" : "Wrong user or password", |
This file contains hidden or 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
| function createCORSRequest(method, url) { | |
| var xhr = new XMLHttpRequest(); | |
| if ("withCredentials" in xhr) { | |
| // XHR for Chrome/Firefox/Opera/Safari. | |
| xhr.open(method, url, true); | |
| } else if (typeof XDomainRequest != "undefined") { | |
| // XDomainRequest for IE. | |
| xhr = new XDomainRequest(); | |
| xhr.open(method, url); | |
| } else { |
This file contains hidden or 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
| SetEnvIf Origin "http(s)?://(domain\.com|foo\.org)$" AccessControlAllowOrigin=$0 | |
| Header set Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin | |
| Header set Access-Control-Allow-Methods POST,GET,DELETE,PUT,OPTIONS | |
| Header set Access-Control-Allow-Headers X-Requested-With,AUTH_TOKEN,Content-Type |
This file contains hidden or 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
| match '/signin_foo' => 'sessions#new_foo', :as => :signin_foo | |
| match '/signin_bar' => 'sessions#new_bar', :as => :signin_bar |
This file contains hidden or 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
| def new_foo | |
| redirect_to '/auth/foo/callback' | |
| end | |
| def new_bar | |
| redirect_to '/auth/bar/callback' | |
| end |