예제 #1
0
func TestChatReceive(t *testing.T) {
	tick := message.Tick(42)
	username := "******"
	msg := "How r u guys? aéoaéoaèo"

	testMessage(t, message.Types["chat_receive"], func(w io.Writer) error {
		return builder.SendChatReceive(w, tick, username, msg)
	}, func(conn *message.Conn, t *testing.T) {
		rt, rusername, rmsg := handler.ReadChatReceive(conn)
		if rt != tick {
			t.Fatal("Sent tick", tick, "but received", rt)
		}
		if rusername != username {
			t.Fatal("Sent username", username, "but received", rusername)
		}
		if rmsg != msg {
			t.Fatal("Sent message", msg, "but received", rmsg)
		}
	})
}
예제 #2
0
파일: server.go 프로젝트: emersion/miko
			var angle float32
			var tmpId message.EntityId
			Read(conn, &angle, &tmpId)
			log.Println("Received ball action:", angle, tmpId)

			action.Params = []interface{}{angle, tmpId}
		} else {
			log.Println("Client triggered unknown action:", action.Id)
		}

		ctx.Action.Execute(action, t)
		return nil
	},
	message.Types["chat_send"]: func(ctx *message.Context, conn *message.Conn) error {
		msg := ReadChatSend(conn)

		if !ctx.Auth.HasSession(conn.Id) {
			return errors.New("User not authenticated")
		}

		session := ctx.Auth.GetSession(conn.Id)
		username := session.Username

		log.Println("Broadcasting chat message:", username, msg)

		return conn.Broadcast(func(w io.Writer) error {
			return builder.SendChatReceive(w, ctx.Clock.GetRelativeTick(), username, msg)
		})
	},
}