Skip to content
Snippets Groups Projects
Select Git revision
21 results Searching

system_app.te

Blame
  • pluginapi.go 4.76 KiB
    package main
    
    import (
    	"bufio"
    	"encoding/json"
    	"fmt"
    	"io/ioutil"
    	"log"
    	"net"
    	"strings"
    	"time"
    )
    
    //
    // BEGIN PUSH MESSAGE API
    //
    
    // PApiStatusCode allows the external plugin to determine the
    // type of PApiMessage.data
    type PApiStatusCode int
    
    const (
    	pApiPlayerConnected    PApiStatusCode = iota // Data = player.Id int
    	pApiPlayerDisconnected                       // Data = player.Id int
    )
    
    type PApiMessage struct {
    	Code PApiStatusCode
    	Data interface{}
    }
    
    type PApiMessageJson []byte
    
    type LobbyServerInfo struct {
    	ActivePlayerCount int
    	SpectatorCount    int
    	MaxPlayerCount    int
    }
    
    func NewPApiMessageConnected(p *Player) PApiMessageJson {
    	return newPApiMessage(pApiPlayerConnected, p)
    }
    
    func NewPApiMessageDisconnected(p *Player) PApiMessageJson {
    	return newPApiMessage(pApiPlayerDisconnected, p)
    }
    
    func newPApiMessage(code PApiStatusCode, data interface{}) PApiMessageJson {
    	m := PApiMessage{code, data}
    	j, err := json.Marshal(m)
    	if err != nil {
    		// Marshal fails iff its parameters contain non serialisable data
    		// We must never let that happen anyway
    		panic(err)
    	}
    	return PApiMessageJson(j)
    }
    
    //
    // END PUSH MESSAGE API
    //
    
    type PType int
    
    const (
    	pNotify PType = iota
    	pBot
    )
    
    type Plugin interface {