package main

import (
	"go.uber.org/zap"
	"net/http"
	pb "../protos"
	"../log"
	"../rpc"
	"github.com/coheneye/go-simplejson"
)

func critical_notice(req *http.Request, args *rpc.RpcArgs, result *rpc.RpcResult) {
	p := simplejson.NewFrom(args.Params)
	r := &pb.S_Ntf_EmergencyNotice{
		Id:                   int32(p.Get("id").MustInt64()),
		Title:                p.Get("title").MustString(),
		Content:              p.Get("content").MustString(),
		Time:                 p.Get("start_time").MustInt64(),
		Endat:                p.Get("end_time").MustInt64(),
	}

	log.Info("critical_notice", zap.Int("onlines", Server.GetSessionNum()))

	BroadcastToClient(r)
}

//
func reset_bank_pass(req *http.Request, args *rpc.RpcArgs, result *rpc.RpcResult) {
	p := simplejson.NewFrom(args.Params)
	guid := uint64(p.Get("guid").MustInt64())

	// notify
	ses, err := Server.GetSession(guid)
	if err != nil {
		log.Warn("reset_bank_pass. user offline", zap.Error(err))
		return
	}

	r := &pb.S_UpdateBankPassword{
		Ec:                   int32(pb.ErrCode_OK),
		BankPass:             "",
	}

	SendToClient(ses, guid, r)
}