private void Request_Create_Or_Join_Channel( EPersistenceID player_id, string channel_name, CJoinChatChannelResultMessage result_msg ) { if ( Get_Player_By_Persistence_ID( player_id ) == null ) { result_msg.CreateError = EChannelCreationError.UnknownPlayer; return; } if ( !CServerChatChannel.Is_Client_Channel_Name( channel_name ) ) { result_msg.CreateError = EChannelCreationError.InvalidInternalName; return; } CServerChatChannel channel = Get_Channel_By_Internal_Name( channel_name ); if ( channel == null ) { CChatChannelConfig channel_config = new CChatChannelConfig( channel_name, channel_name, player_id, EChannelGameProperties.User ); channel_config.DestroyWhenEmpty = true; channel_config.AllowsModeration = true; result_msg.CreateError = channel_config.Make_Valid(); if ( result_msg.CreateError != EChannelCreationError.None ) { return; } EChannelID channel_id = Allocate_Channel_ID(); channel = new CServerChatChannel( channel_id, channel_config ); m_Channels.Add( channel_id, channel ); m_ChannelInternalNames.Add( channel_config.InternalName.ToUpper(), channel_id ); } if ( channel.IsServerChannel ) { result_msg.JoinError = EChannelJoinError.NoPermission; return; } result_msg.JoinError = channel.Join_Channel( player_id ); if ( result_msg.JoinError == EChannelJoinError.None ) { channel.Update_Moderator(); Add_Channel_To_Player( player_id, channel.ID ); result_msg.ChannelID = channel.ID; result_msg.ChannelName = channel.ExternalName; result_msg.AnnounceJoinLeave = channel.ShouldAnnounceJoinLeave; channel.Members.Apply( id => result_msg.Add_Member( id ) ); channel.Gagged.Apply( id => result_msg.Add_Gagged( id ) ); Send_Notification_To_Channel( channel.ID, player_id, EChatNotification.Player_Joined_Channel, player_id ); if ( channel.Update_Moderator() ) { Send_Notification_To_Channel( channel.ID, channel.Moderator, EChatNotification.New_Moderator, EPersistenceID.Invalid ); } result_msg.Moderator = channel.Moderator; } else { Request_Destroy_Channel( channel.ID ); } }
private void Request_Create_Channel( CChatChannelConfig channel_config, CCreateChatChannelResponseServerMessage response_msg ) { response_msg.Error = channel_config.Make_Valid(); if ( response_msg.Error != EChannelCreationError.None ) { return; } if ( channel_config.CreatorID != EPersistenceID.Invalid ) { if ( Get_Player_By_Persistence_ID( channel_config.CreatorID ) == null ) { response_msg.Error = EChannelCreationError.UnknownPlayer; return; } } if ( Get_Channel_By_Internal_Name( channel_config.InternalName ) != null ) { response_msg.Error = EChannelCreationError.DuplicateInternalName; return; } EChannelID channel_id = Allocate_Channel_ID(); CServerChatChannel new_channel = new CServerChatChannel( channel_id, channel_config ); m_Channels.Add( channel_id, new_channel ); m_ChannelInternalNames.Add( channel_config.InternalName.ToUpper(), channel_id ); response_msg.ChannelID = channel_id; response_msg.ChannelName = channel_config.ExternalName; if ( channel_config.CreatorID != EPersistenceID.Invalid ) { if ( Request_Join_Channel( channel_config.CreatorID, channel_id, EChannelGameProperties.None ) != EChannelJoinError.None ) { response_msg.Error = EChannelCreationError.UnableToAutoJoin; Request_Destroy_Channel( channel_id ); return; } } }