Пример #1
0
func (h *GameHub) Run() {
	log.SetPrefix("GameHub")
	log.SetDebug(true)
	log.Info("Started GameHub")

	h.createDemoRooms()

	//InitTest()
	h.TestQuiz()

	for {
		select {

		// Player entered lobby.
		case p := <-h.register:
			h.players[p.id] = p
			h.connections[p.conn] = true
			h.lobby.addPlayer(p)
			log.Debug("Added Player " + p.id)

		// Player exited website.
		case p := <-h.unregister:
			delete(h.players, p.id)
			delete(h.connections, p.conn)
			close(p.conn.send)
			log.Debug("Player " + p.id + " exited")

		// Distribute broadcast messages to all connections.
		case m := <-h.broadcast:
			if h.handleMessage(m) != true {
				for c := range h.connections {
					select {
					case c.send <- m:
					default:
						delete(h.connections, c)
						close(c.send)
						go c.ws.Close()
					}
				}
			}
		}
	}
}
Пример #2
0
// Create a new applet manager with arguments received from command line.
//
func Applet() *CDApplet {
	args := os.Args
	name := args[0][2:] // Strip ./ in the beginning.
	cda := &CDApplet{
		AppletName:    name,
		ConfFile:      args[3],
		RootDataDir:   args[4],
		ParentAppName: args[5],
		ShareDataDir:  path.Join(args[4], AppletsDir, name),
		CdDbus:        dbus.New(args[2]),

		Templates: make(map[string]*template.Template),
	}

	log.SetPrefix(name)

	//~ cda._cMenuIconId = "";
	return cda
}