private OperationResponse HandleOperationJoinChatChannel(OperationRequest operationRequest) { var operation = new JoinChannel(this.Protocol, operationRequest); if (!operation.IsValid) { return new OperationResponse(operationRequest.OperationCode) { ReturnCode = (short)ResultCode.InvalidOperationParameter, DebugMessage = operation.GetErrorMessage() } } ; Channel channel; if (channels.TryGetValue(operation.ChannelId, out channel)) { ChatSession session; if (chat.SessionCache.TryGetSessionBySessionId(operation.SessionId, out session)) { channel.Join(session); } } return(null); }
private async Task <bool> GetChannelActor(JoinChannel msg) { if (string.IsNullOrEmpty(msg.ChannelName)) { return(false); } if (_ChannelActors.ContainsKey(msg.ChannelName)) { Logger.Log(Akka.Event.LogLevel.InfoLevel, $"Actor for channel '{msg.ChannelName}' already present."); return(false); } var configObject = await _ChannelConfigurationActor.Ask(new GetConfigurationForChannel(msg.ChannelName)); var config = configObject as ChannelConfiguration; if (!config.ConnectedToChannel) { config.ConnectedToChannel = true; _ChannelConfigurationActor.Tell(new SaveConfigurationForChannel(msg.ChannelName, config)); } var child = Context.ActorOf(ChannelActor.Props(config), $"channel_{msg.ChannelName}"); _ChannelActors.Add(msg.ChannelName, child); // Track followers for that channel? _FollowerActor.Tell(new TrackNewFollowers(msg.ChannelName, config.ChannelId)); return(true); }
public async Task Process(JoinChannel joinChannel) { if (!IsLoggedIn) { return; } if (!await state.ChannelManager.CanJoin(User.AccountID, joinChannel.ChannelName)) { await SendCommand(new JoinChannelResponse() { Success = false, Reason = "you don't have permission to join this channel", ChannelName = joinChannel.ChannelName }); return; } var channel = state.Rooms.GetOrAdd(joinChannel.ChannelName, (n) => new Channel() { Name = joinChannel.ChannelName, }); if (channel.Password != joinChannel.Password) { await SendCommand(new JoinChannelResponse() { Success = false, Reason = "invalid password", ChannelName = joinChannel.ChannelName }); return; } var added = channel.Users.TryAdd(Name, User); var users = channel.Users.Keys.ToArray(); await SendCommand(new JoinChannelResponse() { Success = true, ChannelName = joinChannel.ChannelName, Channel = new ChannelHeader() { ChannelName = channel.Name, Password = channel.Password, Topic = channel.Topic, Users = new List <string>(users) } }); await state.OfflineMessageHandler.SendMissedMessages(this, SayPlace.Channel, joinChannel.ChannelName, User.AccountID); if (added) { await state.Broadcast(users, new ChannelUserAdded { ChannelName = channel.Name, UserName = Name }); } }
protected virtual void RealmSocket_OnCharacterLogonResponse(CharacterLogonResponse Packet) { RealmCharacterActionResult result = Packet.Result; if (result == RealmCharacterActionResult.Success) { ChannelListRequest bnetPacket = new ChannelListRequest(); this.Chat.SendPacket(bnetPacket); EnterChatRequest bnetPacket2 = new EnterChatRequest(this.Hero.Name); this.Chat.SendPacket(bnetPacket2); JoinChannel bnetPacket3 = new JoinChannel("Diablo II", true); this.Chat.SendPacket(bnetPacket3); } }
private bool GetChannelActor(JoinChannel msg) { if (_ChannelActors.ContainsKey(msg.ChannelName)) { Logger.Log(Akka.Event.LogLevel.InfoLevel, $"Actor for channel '{msg.ChannelName}' already present."); return false; } var config = DataContext.GetConfigurationForChannel(msg.ChannelName); var child = Context.ActorOf(ChannelActor.Props(config), $"channel_{msg.ChannelName}"); _ChannelActors.Add(msg.ChannelName, child); return true; }
async Task Process(JoinChannel joinChannel) { if (!IsLoggedIn) { return; } var channel = state.Rooms.GetOrAdd(joinChannel.ChannelName, (n) => new Channel() { Name = joinChannel.ChannelName, }); if (channel.Password != joinChannel.Password) { await SendCommand(new JoinChannelResponse() { Success = false, Reason = "invalid password", ChannelName = joinChannel.ChannelName }); } var added = channel.Users.TryAdd(Name, User); var users = channel.Users.Keys.ToArray(); await SynchronizeUsersToMe(users); await SendCommand(new JoinChannelResponse() { Success = true, ChannelName = joinChannel.ChannelName, Channel = new ChannelHeader() { ChannelName = channel.Name, Password = channel.Password, Topic = channel.Topic, TopicSetBy = channel.TopicSetBy, TopicSetDate = channel.TopicSetDate, Users = new List <string>(users) } }); if (added) { await Broadcast(users.Where(x => x != Name), new ChannelUserAdded { ChannelName = channel.Name, UserName = Name }, Name); } }
void HandleJoinChannel(JoinChannel packet) { AreaTableRecord zone = CliDB.AreaTableStorage.LookupByKey(GetPlayer().GetZoneId()); if (packet.ChatChannelId != 0) { ChatChannelsRecord channel = CliDB.ChatChannelsStorage.LookupByKey(packet.ChatChannelId); if (channel == null) { return; } if (zone == null || !GetPlayer().CanJoinConstantChannelInZone(channel, zone)) { return; } } if (string.IsNullOrEmpty(packet.ChannelName)) { return; } if (packet.ChannelName.IsNumber()) { return; } ChannelManager cMgr = ChannelManager.ForTeam(GetPlayer().GetTeam()); if (cMgr != null) { Channel channel = cMgr.GetJoinChannel((uint)packet.ChatChannelId, packet.ChannelName, zone); if (channel != null) { channel.JoinChannel(GetPlayer(), packet.Password); } } }
private bool GetChannelActor(JoinChannel msg) { if (string.IsNullOrEmpty(msg.ChannelName)) { return(false); } if (_ChannelActors.ContainsKey(msg.ChannelName)) { Logger.Log(Akka.Event.LogLevel.InfoLevel, $"Actor for channel '{msg.ChannelName}' already present."); return(false); } var config = _ChannelConfigurationActor.Ask <ChannelConfiguration>(new GetConfigurationForChannel(msg.ChannelName)).GetAwaiter().GetResult(); var child = Context.ActorOf(ChannelActor.Props(config), $"channel_{msg.ChannelName}"); _ChannelActors.Add(msg.ChannelName, child); // Track followers for that channel? _FollowerActor.Tell(new TrackNewFollowers(msg.ChannelName, config.ChannelId)); return(true); }
public async Task Process(JoinChannel joinChannel) { if (!IsLoggedIn) { return; } if (!await server.ChannelManager.CanJoin(User.AccountID, joinChannel.ChannelName)) { await SendCommand(new JoinChannelResponse() { Success = false, Reason = "you don't have permission to join this channel", ChannelName = joinChannel.ChannelName }); return; } var channel = server.Channels.GetOrAdd(joinChannel.ChannelName, (n) => new Channel() { Name = joinChannel.ChannelName, }); if (!string.IsNullOrEmpty(channel.Password) && (channel.Password != joinChannel.Password)) { await SendCommand(new JoinChannelResponse() { Success = false, Reason = "invalid password", ChannelName = joinChannel.ChannelName }); return; } var added = channel.Users.TryAdd(Name, User); if (!added) { await SendCommand(new JoinChannelResponse() { Success = false, Reason = "You are already in this channel", ChannelName = joinChannel.ChannelName }); return; } var visibleUsers = !channel.IsDeluge ? channel.Users.Keys.ToList() : channel.Users.Keys.Where(x => server.CanUserSee(Name, x)).ToList(); var canSeeMe = !channel.IsDeluge ? channel.Users.Keys.ToList() : channel.Users.Keys.Where(x => server.CanUserSee(x, Name)).ToList(); await server.TwoWaySyncUsers(Name, canSeeMe); // mutually sync user statuses // send response with the list await SendCommand(new JoinChannelResponse() { Success = true, ChannelName = joinChannel.ChannelName, Channel = new ChannelHeader() { ChannelName = channel.Name, Password = channel.Password, Topic = channel.Topic, Users = visibleUsers, // for zk use cansee test to not send all users IsDeluge = channel.IsDeluge } }); // send missed messages server.OfflineMessageHandler.SendMissedMessagesAsync(this, SayPlace.Channel, joinChannel.ChannelName, User.AccountID, channel.IsDeluge ? OfflineMessageHandler.DelugeMessageResendCount : OfflineMessageHandler.MessageResendCount); // send self to other users who can see if (added) { await server.Broadcast(canSeeMe, new ChannelUserAdded { ChannelName = channel.Name, UserName = Name }); } }
//public void ResetGame(ResetGame resetGame) //{ // if (state.games.TryGetValue(resetGame.Id , out var value)) // { // // this is why () should not be the method call syntax // // .Invoke included for readablity // getOnUpdateScore(resetGame.Id).Invoke(value.Reset()); // } //} public IAsyncEnumerable <GameStateUpdate> JoinChannel(JoinChannel joinChannel) { return(state.games.GetOrThrow(joinChannel.Id).GetReader()); }
void HandleJoinChannel(JoinChannel packet) { AreaTableRecord zone = CliDB.AreaTableStorage.LookupByKey(GetPlayer().GetZoneId()); if (packet.ChatChannelId != 0) { ChatChannelsRecord channel = CliDB.ChatChannelsStorage.LookupByKey(packet.ChatChannelId); if (channel == null) { return; } if (zone == null || !GetPlayer().CanJoinConstantChannelInZone(channel, zone)) { return; } } if (packet.ChannelName.IsEmpty() || char.IsDigit(packet.ChannelName[0])) { ChannelNotify channelNotify = new(); channelNotify.Type = ChatNotify.InvalidNameNotice; channelNotify.Channel = packet.ChannelName; SendPacket(channelNotify); return; } if (packet.Password.Length > 127) { Log.outError(LogFilter.Network, $"Player {GetPlayer().GetGUID()} tried to create a channel with a password more than 127 characters long - blocked"); return; } ChannelManager cMgr = ChannelManager.ForTeam(GetPlayer().GetTeam()); if (cMgr != null) { if (packet.ChatChannelId != 0) { // system channel Channel channel = cMgr.GetSystemChannel((uint)packet.ChatChannelId, zone); if (channel != null) { channel.JoinChannel(GetPlayer()); } } else { // custom channel if (packet.ChannelName.Length > 31) { Log.outError(LogFilter.Network, $"Player {GetPlayer().GetGUID()} tried to create a channel with a name more than 31 characters long - blocked"); return; } Channel channel = cMgr.GetCustomChannel(packet.ChannelName); if (channel != null) { channel.JoinChannel(GetPlayer(), packet.Password); } else { channel = cMgr.CreateCustomChannel(packet.ChannelName); if (channel != null) { channel.SetPassword(packet.Password); channel.JoinChannel(GetPlayer(), packet.Password); } } } } }
//public async void Send(ResetGame inputs) //{ // try // { // await connection.InvokeAsync(nameof(ResetGame), inputs); // } // catch (TimeoutException) // { // } // catch (InvalidOperationException) // { // } //} //public async void Send(string game, ColorChanged colorChanged) //{ // try // { // await connection.InvokeAsync(nameof(ColorChanged), game, colorChanged); // } // catch (TimeoutException) // { // } // catch (InvalidOperationException) // { // } //} //public async void Send(string game, NameChanged nameChanged) //{ // try // { // await connection.InvokeAsync(nameof(NameChanged), game, nameChanged); // } // catch (TimeoutException) // { // } // catch (InvalidOperationException) // { // } //} public IAsyncEnumerable <GameStateUpdate> JoinChannel(JoinChannel joinChannel) { return(connection.StreamAsync <GameStateUpdate>(nameof(JoinChannel), joinChannel)); }