Skip to content

Instantly share code, notes, and snippets.

@marmistrz
Created July 2, 2018 12:36
Show Gist options
  • Save marmistrz/123b358bfd1f041b1984d919a2805824 to your computer and use it in GitHub Desktop.
Save marmistrz/123b358bfd1f041b1984d919a2805824 to your computer and use it in GitHub Desktop.
# HG changeset patch
# User Marcin Mielniczuk <marmistrz.dev@zoho.eu>
Add cargo/rls build artifacts to .gitignore
---
.gitignore | 2 ++
1 file changed, 2 insertions(+)
diff --git a/.gitignore b/.gitignore
index 25b4c49a9..fe2db7699 100644
--- a/.gitignore
+++ b/.gitignore
@@ -81,3 +81,5 @@ xcuserdata
*.mode1v3
*.mode2v3
Testing/*
+gameServer2/rls
+gameServer2/target
--
2.18.0
From 20398a279c2fe889afb3330bb104b84e8eec3eda Mon Sep 17 00:00:00 2001
From: Marcin Mielniczuk <marmistrz.dev@zoho.eu>
Date: Mon, 2 Jul 2018 14:33:25 +0200
Subject: [PATCH 2/2] Implement to_raw_protocol for Rnd and enable tests.
---
gameServer2/src/protocol/messages.rs | 10 +++++++---
gameServer2/src/protocol/test.rs | 7 ++++++-
2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/gameServer2/src/protocol/messages.rs b/gameServer2/src/protocol/messages.rs
index 21ff1de18..54a57a646 100644
--- a/gameServer2/src/protocol/messages.rs
+++ b/gameServer2/src/protocol/messages.rs
@@ -130,8 +130,12 @@ impl GameCfg {
}
}
-impl<'a> HWProtocolMessage {
- pub fn to_raw_protocol(&self) -> String {
+impl HWProtocolMessage {
+ /** Converts the message to a raw `String`, which can be sent over the network.
+ *
+ * This is the inverse of the `message` parser.
+ */
+ pub(crate) fn to_raw_protocol(&self) -> String {
use self::HWProtocolMessage::*;
match self {
Ping => "PING\n\n".to_string(),
@@ -160,7 +164,7 @@ impl<'a> HWProtocolMessage {
format!("JOIN\n{}\n{}\n\n", name, arg),
Follow(name) =>
format!("FOLLOW\n{}\n\n", name),
- //Rnd(Vec<String>), ???
+ Rnd(v) => format!("CMD\nRND {}\n\n", v.join(" ")),
Kick(name) => format!("KICK\n{}\n\n", name),
Ban(name, reason, time) =>
format!("BAN\n{}\n{}\n{}\n\n", name, reason, time),
diff --git a/gameServer2/src/protocol/test.rs b/gameServer2/src/protocol/test.rs
index 90b590193..14bd763ea 100644
--- a/gameServer2/src/protocol/test.rs
+++ b/gameServer2/src/protocol/test.rs
@@ -12,6 +12,11 @@ use super::messages::{
// Due to inability to define From between Options
trait Into2<T>: Sized { fn into2(self) -> T; }
impl <T> Into2<T> for T { fn into2(self) -> T { self } }
+impl Into2<Vec<String>> for Vec<Ascii> {
+ fn into2(self) -> Vec<String> {
+ self.into_iter().map(|x| x.0).collect()
+ }
+}
impl Into2<String> for Ascii { fn into2(self) -> String { self.0 } }
impl Into2<Option<String>> for Option<Ascii>{
fn into2(self) -> Option<String> { self.map(|x| {x.0}) }
@@ -89,7 +94,7 @@ pub fn gen_proto_msg() -> BoxedStrategy<HWProtocolMessage> where {
15 => CreateRoom(Ascii, Option<Ascii>),
16 => JoinRoom(Ascii, Option<Ascii>),
17 => Follow(Ascii),
- //18 => Rnd(Vec<String>),
+ 18 => Rnd(Vec<Ascii>),
19 => Kick(Ascii),
20 => Ban(Ascii, Ascii, u32),
21 => BanIP(Ascii, Ascii, u32),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment