コード例 #1
0
ファイル: master.go プロジェクト: toophy/chat_svr
// 响应网络事件
func (this *MasterThread) On_netEvent(m *toogo.Tmsg_net) bool {

	name_fix := m.Name
	if len(name_fix) == 0 {
		name_fix = fmt.Sprintf("Conn[%d]", m.SessionId)
	}

	switch m.Msg {
	case "listen failed":
		this.LogFatal("%s : Listen failed[%s]", name_fix, m.Info)

	case "listen ok":
		this.LogInfo("%s : Listen(%s) ok.", name_fix, toogo.GetSessionById(m.SessionId).GetIPAddress())

	case "accept failed":
		this.LogFatal(m.Info)
		return false

	case "accept ok":
		this.LogDebug("%s : Accept ok", name_fix)

	case "connect failed":
		this.LogError("%s : Connect failed[%s]", name_fix, m.Info)

	case "connect ok":
		this.LogDebug("%s : Connect ok", name_fix)

		p := toogo.NewPacket(128, m.SessionId)

		msgLogin := new(proto.S2G_registe)
		msgLogin.Sid = toogo.Tgid_make_Sid(1, 1)
		msgLogin.Write(p, uint64(0))

		this.LogDebug("toMailId=%d", p.GetToMailId())

		p.PacketWriteOver()

		toogo.SendPacket(p)

	case "read failed":
		this.LogError("%s : Connect read[%s]", name_fix, m.Info)

	case "pre close":
		this.LogDebug("%s : Connect pre close", name_fix)

	case "close failed":
		this.LogError("%s : Connect close failed[%s]", name_fix, m.Info)

	case "close ok":
		this.LogDebug("%s : Connect close ok.", name_fix)
	}

	return true
}
コード例 #2
0
ファイル: main.go プロジェクト: toophy/chat_client
// 响应网络事件
func (this *MasterThread) On_netEvent(m *toogo.Tmsg_net) bool {

	name_fix := m.Name
	if len(name_fix) == 0 {
		name_fix = fmt.Sprintf("Conn[%d]", m.SessionId)
	}

	switch m.Msg {
	case "listen failed":
		this.LogFatal("%s : Listen failed[%s]", name_fix, m.Info)

	case "listen ok":
		this.LogInfo("%s : Listen(%s) ok.", name_fix, toogo.GetSessionById(m.SessionId).GetIPAddress())

	case "accept failed":
		this.LogFatal(m.Info)
		return false

	case "accept ok":
		this.LogDebug("%s : Accept ok", name_fix)

	case "connect failed":
		this.LogError("%s : Connect failed[%s]", name_fix, m.Info)

	case "connect ok":
		this.LogDebug("%s : Connect ok", name_fix)

		p := toogo.NewPacket(128, m.SessionId)

		msgLogin := new(proto.C2G_login)
		msgLogin.Account = "liusl"
		msgLogin.Time = 123
		msgLogin.Sign = "wokao"
		msgLogin.Write(p)
		this.LogInfo("send C2G_login")

		toogo.SendPacket(p)

	case "read failed":
		this.LogError("%s : Connect read[%s]", name_fix, m.Info)

	case "pre close":
		this.LogDebug("%s : Connect pre close", name_fix)

	case "close failed":
		this.LogError("%s : Connect close failed[%s]", name_fix, m.Info)

	case "close ok":
		this.LogDebug("%s : Connect close ok.", name_fix)
	}

	return true
}
コード例 #3
0
ファイル: main.go プロジェクト: toophy/chat_client
func (this *MasterThread) on_g2c_login_ret(pack *toogo.PacketReader, sessionId uint64) bool {
	msg := new(proto.G2C_login_ret)
	msg.Read(pack)

	this.LogInfo("on_g2c_login_ret")

	p := toogo.NewPacket(128, sessionId)
	if p != nil {
		msgSend := new(proto.C2S_chat)
		msgSend.Channel = 1
		msgSend.Data = "你好,世界!"
		msgSend.Write(p)

		toogo.SendPacket(p)
	}

	return true
}
コード例 #4
0
ファイル: net_msg_proc.go プロジェクト: toophy/chat_svr
func (this *MasterThread) on_c2s_chat(pack *toogo.PacketReader, sessionId uint64) bool {
	msg := proto.C2S_chat{}
	msg.Read(pack)

	this.LogInfo("Say : %s", msg.Data)

	// 广播消息
	p := toogo.NewPacket(128, sessionId)

	msgChat := new(proto.S2C_chat)
	msgChat.Data = msg.Data
	msgChat.Write(p, pack.LinkTgid)

	p.PacketWriteOver()
	toogo.SendPacket(p)

	return true
}