-
+
{chat || '\u00A0'}
{scoreText()}
{player.name}
![]()
diff --git a/client/src/events.jsx b/client/src/events.jsx
index 07a8262b..0083e0bb 100644
--- a/client/src/events.jsx
+++ b/client/src/events.jsx
@@ -212,6 +212,14 @@ function registerEvents(store) {
return store.dispatch(actions.setInstance(v));
}
+ function setInstanceChat(v) {
+ return store.dispatch(actions.setInstanceChat(v));
+ }
+
+ function setChatWheel(v) {
+ return store.dispatch(actions.setChatWheel(v));
+ }
+
function setItemInfo(v) {
return store.dispatch(actions.setItemInfo(v));
}
@@ -318,12 +326,14 @@ function registerEvents(store) {
setAccountInstances,
setActiveItem,
setActiveSkill,
+ setChatWheel,
setDemo,
setConstructList,
setNewConstruct,
setGame,
setEmail,
setInstance,
+ setInstanceChat,
setItemInfo,
setInvite,
setPing,
diff --git a/client/src/reducers.jsx b/client/src/reducers.jsx
index c24519e3..24ced707 100644
--- a/client/src/reducers.jsx
+++ b/client/src/reducers.jsx
@@ -25,6 +25,8 @@ module.exports = {
demo: createReducer(null, 'SET_DEMO'),
chatShow: createReducer(null, 'SET_CHAT_SHOW'),
+ chatWheel: createReducer([], 'SET_CHAT_WHEEL'),
+
combiner: createReducer([], 'SET_COMBINER'),
constructs: createReducer([], 'SET_CONSTRUCTS'),
constructEditId: createReducer(null, 'SET_CONSTRUCT_EDIT_ID'),
@@ -34,6 +36,7 @@ module.exports = {
invite: createReducer(null, 'SET_INVITE'),
info: createReducer(null, 'SET_INFO'),
instance: createReducer(null, 'SET_INSTANCE'),
+ instanceChat: createReducer(null, 'SET_INSTANCE_CHAT'),
instances: createReducer([], 'SET_INSTANCES'),
itemEquip: createReducer(null, 'SET_ITEM_EQUIP'),
itemInfo: createReducer({ combos: [], items: [] }, 'SET_ITEM_INFO'),
diff --git a/client/src/socket.jsx b/client/src/socket.jsx
index ec174322..818f8a53 100644
--- a/client/src/socket.jsx
+++ b/client/src/socket.jsx
@@ -67,6 +67,10 @@ function createSocket(events) {
send(['InstanceState', { instance_id: instanceId }]);
}
+ function sendInstanceChat(instanceId, index) {
+ send(['InstanceChat', { instance_id: instanceId, index }]);
+ }
+
function sendVboxAccept(instanceId, group, index) {
send(['VboxAccept', { instance_id: instanceId, group, index }]);
events.clearInstance();
@@ -253,8 +257,11 @@ function createSocket(events) {
QueueJoined: () => events.notify('you have joined the pvp queue'),
InviteRequested: () => events.notify('pvp queue request received'),
Invite: code => events.setInvite(code),
+ InstanceChat: chat => events.setInstanceChat(chat),
+ ChatWheel: wheel => events.setChatWheel(wheel),
Joining: () => events.notify('searching for instance...'),
+ Processing: () => true,
Error: errHandler,
};
@@ -358,6 +365,7 @@ function createSocket(events) {
sendInstanceState,
sendInstanceInvite,
sendInstanceJoin,
+ sendInstanceChat,
sendVboxAccept,
sendVboxApply,
diff --git a/server/src/account.rs b/server/src/account.rs
index 11776a4b..56921e2c 100644
--- a/server/src/account.rs
+++ b/server/src/account.rs
@@ -65,6 +65,19 @@ pub fn select(db: &Db, id: Uuid) -> Result
{
Account::try_from(row)
}
+pub fn chat_wheel(_db: &Db, _id: Uuid) -> Result, Error> {
+ return Ok(vec![
+ "gl".to_string(),
+ "hf".to_string(),
+ "gg".to_string(),
+ "thx".to_string(),
+ "nice".to_string(),
+ "hmm".to_string(),
+ "ok".to_string(),
+ "...".to_string(),
+ ])
+}
+
pub fn select_name(db: &Db, name: &String) -> Result {
let query = "
SELECT id, name, balance, subscribed, img
diff --git a/server/src/events.rs b/server/src/events.rs
index 7064313c..3b24200c 100644
--- a/server/src/events.rs
+++ b/server/src/events.rs
@@ -58,7 +58,9 @@ pub enum Event {
Invite(Id),
Join(Id, String),
Joined(Id),
- Chat(Id, Uuid, String)
+
+ Chat(Id, Uuid, String),
+ ChatClear(Id, Uuid),
}
struct WsClient {
@@ -66,6 +68,7 @@ struct WsClient {
account: Option,
tx: Sender,
subs: HashSet,
+ chat: Option<(Uuid, String)>,
pvp: bool,
invite: Option,
}
@@ -121,7 +124,15 @@ impl Events {
None => None,
};
- let client = WsClient { id, tx, account: account_id, subs: HashSet::new(), pvp: false, invite: None };
+ let client = WsClient { id,
+ tx,
+ account: account_id,
+ subs: HashSet::new(),
+ pvp: false,
+ invite: None,
+ chat: None,
+ };
+
self.clients.insert(id, client);
info!("clients={:?}", self.clients.len());
@@ -216,7 +227,7 @@ impl Events {
}
// create the req for the already queued opponent
- if let Some(opp_req) = match self.clients.iter_mut().find(|(_c_id, c)| c.pvp) {
+ if let Some(opp_req) = match self.clients.iter_mut().find(|(c_id, c)| c.pvp && **c_id != id) {
Some((q_id, q)) => {
q.pvp = false;
Some(PvpRequest { id: *q_id, account: q.account.unwrap(), tx: q.tx.clone() })
@@ -292,6 +303,52 @@ impl Events {
return Ok(());
},
+ Event::Chat(id, instance, msg) => {
+ // set the chat state of this connection
+ {
+ let c = self.clients.get_mut(&id)
+ .ok_or(format_err!("connection not found id={:?}", id))?;
+
+ if c.chat.is_some() {
+ return Err(err_msg("you must wait"));
+ }
+
+ c.chat = Some((instance, msg));
+ }
+
+ // now collect all listeners of this instance
+
+ let chat_state: HashMap = self.clients.iter()
+ .filter(|(_id, c)| c.account.is_some())
+ .filter(|(_id, c)| match c.chat {
+ Some(ref chat) => chat.0 == instance,
+ None => false,
+ })
+ .map(|(_id, c)| (c.account.unwrap(), c.chat.clone().unwrap().1))
+ .collect();
+
+ return self.event(Event::Push(instance, RpcMessage::InstanceChat(chat_state)));
+ },
+
+ Event::ChatClear(id, instance) => {
+ {
+ match self.clients.get_mut(&id) {
+ Some(c) => c.chat = None,
+ None => (),
+ };
+ }
+
+ let chat_state: HashMap = self.clients.iter()
+ .filter(|(_id, c)| c.account.is_some())
+ .filter(|(_id, c)| match c.chat {
+ Some(ref chat) => chat.0 == instance,
+ None => false,
+ })
+ .map(|(_id, c)| (c.account.unwrap(), c.chat.clone().unwrap().1))
+ .collect();
+
+ return self.event(Event::Push(instance, RpcMessage::InstanceChat(chat_state)));
+ }
}
}
}
diff --git a/server/src/instance.rs b/server/src/instance.rs
index b170d9ce..4f4ae29e 100644
--- a/server/src/instance.rs
+++ b/server/src/instance.rs
@@ -1,4 +1,5 @@
use std::fs::File;
+use std::collections::{HashMap};
use uuid::Uuid;
@@ -31,6 +32,8 @@ enum InstancePhase {
Finished,
}
+pub type ChatState = HashMap;
+
#[derive(Debug,Clone,Serialize,Deserialize)]
struct Round {
game_id: Option,
diff --git a/server/src/rpc.rs b/server/src/rpc.rs
index 860b89ce..2dfb9589 100644
--- a/server/src/rpc.rs
+++ b/server/src/rpc.rs
@@ -1,5 +1,7 @@
use std::time::{Instant};
-use std::thread::spawn;
+use std::thread::{spawn, sleep};
+use std::time;
+
use std::str;
use uuid::Uuid;
@@ -21,7 +23,7 @@ use account;
use construct::{Construct};
use events::{Event};
use game::{Game, game_state, game_skill, game_skill_clear, game_ready};
-use instance::{Instance, instance_state, instance_practice, instance_ready, instance_abandon, demo};
+use instance::{Instance, ChatState, instance_state, instance_practice, instance_ready, instance_abandon, demo};
use item::{Item, ItemInfoCtr, item_info};
use mtx;
use mail;
@@ -50,6 +52,8 @@ pub enum RpcMessage {
ItemInfo(ItemInfoCtr),
InstanceState(Instance),
+ InstanceChat(ChatState),
+ ChatWheel(Vec),
EmailState(Option),
SubscriptionState(Option),
@@ -66,6 +70,8 @@ pub enum RpcMessage {
Invite(String),
Joining(()),
+ Processing(()),
+
Error(String),
}
@@ -102,6 +108,7 @@ pub enum RpcRequest {
InstanceAbandon { instance_id: Uuid },
InstanceReady { instance_id: Uuid },
InstanceState { instance_id: Uuid },
+ InstanceChat { instance_id: Uuid, index: usize },
VboxAccept { instance_id: Uuid, group: usize, index: usize },
VboxDiscard { instance_id: Uuid },
@@ -164,21 +171,22 @@ impl Connection {
return Err(err_msg("subscribe to unlock chat"))
}
- let chat = vec![
- "gl",
- "hf",
- "gg",
- "thx",
- "nice",
- "hmm",
- "ok",
- "...",
- ];
+ let wheel = account::chat_wheel(&db, account.id)?;
- self.events.send(Event::Chat(self.id, instance_id, chat[index]))?;
+ if let Some(c) = wheel.get(index) {
+ self.events.send(Event::Chat(self.id, instance_id, c.to_string()))?;
+ } else {
+ return Err(err_msg("invalid chat index"));
+ }
- // evnts sends to subs
- Ok(RpcMessage::Joining(()))
+ let events_tx = self.events.clone();
+ let id = self.id;
+ spawn(move || {
+ sleep(time::Duration::from_secs(3));
+ events_tx.send(Event::ChatClear(id, instance_id)).unwrap();
+ });
+
+ Ok(RpcMessage::Processing(()))
},
_ => {
// all good, let's make a tx and process
@@ -337,6 +345,9 @@ impl Handler for Connection {
let team = account::team(&mut tx, &a).unwrap();
self.send(RpcMessage::AccountTeam(team)).unwrap();
+ let wheel = account::chat_wheel(&db, a.id).unwrap();
+ self.send(RpcMessage::ChatWheel(wheel)).unwrap();
+
// tx should do nothing
tx.commit().unwrap();
} else {