summaryrefslogtreecommitdiff
path: root/server/object/object.go
blob: e0d02399383006645607ffe04083bda0df01799f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package object

import (
	"citrons.xyz/talk/proto"
	"citrons.xyz/talk/server/session"
)

type Object interface {
	SendRequest(session.Request)
	InfoFor(uid string) proto.Object
}

type World struct {
	objects map[string]Object
}

func NewWorld() *World {
	return &World {make(map[string]Object)}
}

func (w *World) GetObject(id string) Object {
	return w.objects[id]
}

func (w *World) PutObject(id string, o Object) {
	w.objects[id] = o
}

func (w *World) RemoveObject(id string) {
	w.objects[id] = nil
}

func (w *World) NewObject(o Object) string {
	id := proto.GenId()
	w.PutObject(id, o)
	return id
}