Ejemplo n.º 1
0
//---------------------------------------------------------- Add a timeout event
func Add(Type int16, user_id int32, timeout int64, params []byte) int32 {
	event_id := db.NextVal(EVENTID_GEN)
	timer.Add(event_id, timeout, _event_ch)

	event := &Event{Type: Type, UserId: user_id, EventId: event_id, Timeout: timeout, Params: params}
	_events_lock.Lock()
	_events[event_id] = event
	_events_lock.Unlock()

	// store to db
	event_tbl.Add(event)

	return event_id
}
Ejemplo n.º 2
0
//---------------------------------------------------------- create group
func Create(creator_id int32, groupname string) (groupid int32, succ bool) {
	_lock.Lock()
	defer _lock.Unlock()

	if _group_names[groupname] == nil {
		groupid := db.NextVal(GROUP_GEN)
		group := &GroupInfo{GroupId: groupid, Name: groupname, Leader: creator_id}
		group._members._add(creator_id)

		// index
		_groups[groupid] = group
		_group_names[groupname] = group

		// save
		_save(group)

		return groupid, true
	}

	return 0, false
}