You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
713 B

  1. package main
  2. import (
  3. "fmt"
  4. "zinx/ziface"
  5. "zinx/zinx_app_demo/mmo_game/core"
  6. "zinx/znet"
  7. )
  8. //当客户端建立连接的时候的hook函数
  9. func OnConnecionAdd(conn ziface.IConnection) {
  10. temp_pid := 1
  11. //创建一个玩家
  12. player := core.NewPlayer(conn, int32(temp_pid))
  13. //同步当前的PlayerID给客户端, 走MsgID:1 消息
  14. player.SyncPid()
  15. //同步当前玩家的初始化坐标信息给客户端,走MsgID:200消息
  16. player.BroadCastStartPosition()
  17. fmt.Println("=====> Player pidId = ", temp_pid, " arrived ====")
  18. }
  19. func main() {
  20. //创建服务器句柄
  21. s := znet.NewServer()
  22. //注册客户端连接建立和丢失函数
  23. s.SetOnConnStart(OnConnecionAdd)
  24. //启动服务
  25. s.Serve()
  26. }