コード例 #1
0
 private void OnInviteFriends(object sender, RoutedEventArgs e)
 {
     if (conv == null)
     {
         var friends = playerDCListView.SelectedItems.Cast<PlayerDC>();
         var c = new ConversationDC()
         {
             Host = mainWindow.Player,
             Participants = friends
         };
         mainWindow.Server.CreateConversation(c);
     }
     else
     {
         //conversation already existes, add friends to conv...
     }
 }
コード例 #2
0
 public static ConversationDC ConversationToConversationDC(Conversation conv)
 {
     ConversationDC convDC = null;
     using (var db = new BomberDbContext())
     {
         var q = (from co in db.Conversations
                   where co.ConversationId == conv.ConversationId
                   select co).ToList();
         if (q.Count > 0)
         {
             var c = q.ElementAt(0);
             convDC = new ConversationDC()
             {
                 ConversationId = c.ConversationId,
                 ConversationLog = c.ConversationLog,
                 Host = PlayerToPlayerDC(c.Host),
                 Participants = PlayersToPlayerDCs(c.Players)
             };
         }
     }
     return convDC;
 }
コード例 #3
0
 public void SendConversationMessage(ConversationDC msgContainer)
 {
     if (msgContainer.NewMessageType == 1)
     {
         if (Conversations.Keys.Contains(msgContainer.ConversationId))
         {
             var cm = Conversations[msgContainer.ConversationId];
             cm.TriggerAudioMessageEvent(
                 msgContainer.NewAudioMessageBuffer,
                 msgContainer.NewAudioMessageBytesRecorded,
                 msgContainer.MessageSenderPlayerId);
         }
         return;
     }
     //using (var db = new BomberDbContext())
     //{
     //    var q = (from c in db.Conversations
     //             where c.ConversationId == msgContainer.ConversationId
     //             select c).ToList();
     //    if (q.Count > 0)
     //    {
     //        var conv = q.ElementAt(0);
     //        conv.ConversationLog += msgContainer.NewMessage + " \n";
     //        db.SaveChanges();
     //    }
     //}
     if (Conversations.Keys.Contains(msgContainer.ConversationId))
     {
         var cm = Conversations[msgContainer.ConversationId];
         cm.TriggerMessageEvent(msgContainer.NewMessage);
     }
 }
コード例 #4
0
 private void OnPartyMsgAreaKeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Return && Keyboard.Modifiers == ModifierKeys.Shift)
     {
         _convMsgArea.Text += " \n";
         _convMsgArea.CaretIndex = _convMsgArea.Text.Length;
     }
     else if (e.Key == Key.Return)
     {
         DateTime utcTime = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
         string msg = utcTime.ToString();
         msg += String.Format(" [{0}] : ", mainWindow.Player.Pseudonym);
         msg += _convMsgArea.Text;
         var msgContainer = new ConversationDC()
         {
             ConversationId = Party.ConversationId,
             NewMessage = msg,
             NewMessageType = 0
         };
         mainWindow.Server.SendConversationMessage(msgContainer);
         _convMsgArea.Text = "";
         _convLogScroller.ScrollToEnd();
     }
 }
コード例 #5
0
 public void KillPlayer(ConversationDC conv, PlayerDC player)
 {
     Game.GameContentManager.KillPlayer(player.Login);
 }
コード例 #6
0
 public void UpdatePlayerPosition(ConversationDC conv, PlayerDC player)
 {
     Game.GameContentManager.UpdatePlayerPosition(player.Login, player.PlayerPositionX, player.PlayerPositionY);
 }
コード例 #7
0
 public void RemovePlayerFromParty(PlayerDC player, ConversationDC conv)
 {
     if (player.PlayerId == Player.PlayerId)
     {
         DropConversation(conv);
         return;
     }
     var selectedConv = conversationDCListView.SelectedItem as ConversationDC;
     var q = (from c in conversations where c.ConversationId == conv.ConversationId select c).ToList();
     if (q.Count > 0)
     {
         var c = q.ElementAt(0);
         var q1 = (from p in c.Participants where p.PlayerId == player.PlayerId select p).ToList();
         if (q1.Count > 0)
         {
             c.Participants = c.Participants.ToList();
             ((List<PlayerDC>)c.Participants).Remove(q1.ElementAt(0));
             c.ParticipantsNames = " " + c.Host.Pseudonym + " (Host) \n ";
             foreach (var p in c.Participants)
             {
                 c.ParticipantsNames += p.Pseudonym + ", ";
             }
             c.ParticipantsNames = c.ParticipantsNames.Remove(c.ParticipantsNames.Length - 2);
             partyPage.LoadConversation();
             ConversationsListViewSource.View.Refresh();
         }
     }
 }
コード例 #8
0
 public void ReceiveConversationMessage(ConversationDC c)
 {
     if (c.NewMessageType == 1 && partyPage != null)
     {
         if (LoudSpeakerEnabled && c.MessageSenderPlayerId != Player.PlayerId)
             partyPage.waveProvider.AddSamples(c.NewAudioMessageBuffer, 0, c.NewAudioMessageBytesRecorded);
         return;
     }
     var q = (from co in conversations
              where co.ConversationId == c.ConversationId
              select co).ToList();
     if (q.Count > 0)
     {
         var conv = q.ElementAt(0);
         conv.ConversationLog += c.NewMessage + " \n";
         partyPage.LoadConversation();
     }
 }
コード例 #9
0
 private void KickFromConvEventHandler(PlayerDC player, ConversationDC conv)
 {
     //TODO
 }
コード例 #10
0
 private void JoinConvEventHandler(PlayerDC player, ConversationDC conv)
 {
     //TODO
 }
コード例 #11
0
 private void LeaveConvEventHandler(PlayerDC player, ConversationDC conv)
 {
     Callback.RemovePlayerFromParty(player, conv);
 }
コード例 #12
0
 private void ConvMessageEventHandler(ConversationDC conv)
 {
     var c = new ConversationDC()
     {
         ConversationId = conv.ConversationId,
         NewMessage = conv.NewMessage
     };
     Callback.ReceiveConversationMessage(c);
 }
コード例 #13
0
 public void SwitchMainConversation(ConversationDC conversationDC)
 {
     if (Conversations.Keys.Contains(conversationDC.ConversationId))
     {
         var cm = Conversations[conversationDC.ConversationId];
         PlayerDC p = null;
         if (cm.Conv.Host.PlayerId == Player.PlayerId)
             p = cm.Conv.Host;
         else
         {
             var q = (from m in cm.Conv.Participants where m.PlayerId == Player.PlayerId select m).ToList();
             if (q.Count > 0)
                 p = q.ElementAt(0);
         }
         if (p != null)
         {
             var lastMainRoomId = p.MainRoomId;
             if (Conversations.Keys.Contains(lastMainRoomId))
             {
                 var cm1 = Conversations[lastMainRoomId];
                 cm1.AudioMessageEvent -= AudioMessageEventHandler;
             }
             cm.AudioMessageEvent += AudioMessageEventHandler;
             foreach (var cm2 in Conversations)
             {
                 PlayerDC thisPlayerPossibleOccurence = null;
                 if (cm2.Value.Conv.Host.PlayerId == Player.PlayerId)
                     thisPlayerPossibleOccurence = cm2.Value.Conv.Host;
                 else
                 {
                     var q1 = (from member in cm2.Value.Conv.Participants where member.PlayerId == Player.PlayerId select member).ToList();
                     if (q1.Count > 0)
                         thisPlayerPossibleOccurence = q1.ElementAt(0);
                 }
                 if (thisPlayerPossibleOccurence != null)
                     thisPlayerPossibleOccurence.MainRoomId = conversationDC.ConversationId;
             }
         }
     }
 }
コード例 #14
0
 public void LeaveConversation(ConversationDC Party)
 {
     using (var db = new BomberDbContext())
     {
         var q = (from c in db.Conversations
                  where c.ConversationId == Party.ConversationId
                  select c).ToList();
         var q1 = (from p in db.Players
                   where p.PlayerId == Player.PlayerId
                   select p).ToList();
         if (q.Count > 0 && q1.Count > 0)
         {
             var conv = q.ElementAt(0);
             var thisPlayer = q1.ElementAt(0);
             conv.Players.Remove(thisPlayer);
             var remainingPlayers = conv.Players.Count;
             if (remainingPlayers == 0)
             {
                 db.Conversations.DeleteObject(conv);
                 if (Conversations.Keys.Contains(Party.ConversationId))
                 {
                     var cm = Conversations[Party.ConversationId];
                     cm.TriggerEndOfConvEvent();
                     Conversations.Remove(Party.ConversationId);
                 }
             }
             else if (Conversations.Keys.Contains(Party.ConversationId))
             {
                 var cm = Conversations[Party.ConversationId];
                 var q2 = (from p in cm.Conv.Participants
                           where p.PlayerId == Player.PlayerId
                           select p).ToList();
                 if (q2.Count > 0)
                 {
                     var p = q2.ElementAt(0);
                     cm.Conv.Participants = cm.Conv.Participants.ToList();
                     ((List<PlayerDC>)cm.Conv.Participants).Remove(p);
                     cm.TriggerLeaveEvent(new PlayerDC() { PlayerId = Player.PlayerId });
                     cm.EndOfConvEvent -= EndOfConvEventHandler;
                     cm.JoinEvent -= JoinConvEventHandler;
                     cm.KickEvent -= KickFromConvEventHandler;
                     cm.LeaveEvent -= LeaveConvEventHandler;
                     cm.MessageEvent -= ConvMessageEventHandler;
                 }
             }
             db.SaveChanges();
         }
     }
 }
コード例 #15
0
 public void DeleteConversation(ConversationDC Party)
 {
     using (var db = new BomberDbContext())
     {
         var q = (from c in db.Conversations
                  where c.ConversationId == Party.ConversationId
                  select c).ToList();
         if (q.Count > 0)
         {
             var convToDrop = q.ElementAt(0);
             convToDrop.Players.Clear();
             db.Conversations.DeleteObject(convToDrop);
             db.SaveChanges();
             if (Conversations.Keys.Contains(Party.ConversationId))
             {
                 var cm = Conversations[Party.ConversationId];
                 cm.TriggerEndOfConvEvent();
                 Conversations.Remove(Party.ConversationId);
             }
         }
     }
 }
コード例 #16
0
 public ConversationManager(ConversationDC conv)
 {
     Conv = conv;
 }
コード例 #17
0
 public void InitializeConversation(ConversationDC conversationDC)
 {
     conversationDC.ParticipantsNames = " " + conversationDC.Host.Pseudonym + " (Host) \n ";
     foreach (var p in conversationDC.Participants)
     {
         conversationDC.ParticipantsNames += p.Pseudonym + ", ";
     }
     conversationDC.ParticipantsNames = conversationDC.ParticipantsNames.Remove(conversationDC.ParticipantsNames.Length - 2);
     conversationDC.NewMessage = "";
     var q = (from co in conversations
              where co.ConversationId == conversationDC.ConversationId
              select co).ToList();
     if (q.Count != 0)
     {
         foreach (var co in q)
         {
             ((List<ConversationDC>)conversations).Remove(co);
         }
     }
     ((List<ConversationDC>)conversations).Add(conversationDC);
     ConversationsListViewSource.Source = conversations;
     ConversationsListViewSource.View.Refresh();
 }
コード例 #18
0
 private void EndOfConvEventHandler(ConversationDC conv)
 {
     Callback.DropConversation(conv);
 }
コード例 #19
0
 public void DropConversation(ConversationDC conv)
 {
     var selectedConv = conversationDCListView.SelectedItem as ConversationDC;
     var q = (from c in conversations where c.ConversationId == conv.ConversationId select c).ToList();
     if (q.Count > 0)
     {
         var c = q.ElementAt(0);
         ((List<ConversationDC>)conversations).Remove(c);
         ConversationsListViewSource.Source = conversations;
         ConversationsListViewSource.View.Refresh();
         if (selectedConv != null && selectedConv != c)
         {
             conversationDCListView.SelectedItem = selectedConv;
             partyPage.LoadConversation(selectedConv);
         }
         if (_contentFrame.Content == partyPage && partyPage.Party == c)
             _contentFrame.Content = null;
     }
 }
コード例 #20
0
 private void AudioMessageEventHandler(ConversationDC conv)
 {
     Callback.ReceiveConversationMessage(conv);
 }
コード例 #21
0
 public void OpenGameWindow(ConversationDC conv)
 {
     List<string> allPlayers = new List<string>();
     allPlayers.Add(conv.Host.Login);
     var logins = (from p in conv.Participants select p.Login).ToList();
     allPlayers = allPlayers.Concat<string>(logins).ToList();
     GameLaunching(allPlayers, conv.ConversationId);
 }
コード例 #22
0
 public void GameStartEventHandler(ConversationDC conv)
 {
     Callback.OpenGameWindow(conv);
 }
コード例 #23
0
 public void SpawnBomb(ConversationDC conv, int BombPositionX, int BombPositionY)
 {
     Game.GameContentManager.SpawnBomb(BombPositionX, BombPositionY);
 }
コード例 #24
0
 public void PlayerPositionReplicationEventHandler(ConversationDC conv, PlayerDC player)
 {
     Callback.UpdatePlayerPosition(conv, player);
 }
コード例 #25
0
 public void LoadConversation(ConversationDC conv = null)
 {
     if (conv != null)
         Party = conv;
     PartyListViewSource.Source = new List<ConversationDC>() { Party };
     PartyListViewSource.View.Refresh();
     if (Party.Host.PlayerId == mainWindow.Player.PlayerId)
     {
         _delConvBtn.Visibility = System.Windows.Visibility.Visible;
         _inviteBtn.Visibility = System.Windows.Visibility.Visible;
         _kickBtn.Visibility = System.Windows.Visibility.Visible;
         _leaveBtn.Visibility = System.Windows.Visibility.Hidden;
         _playBtn.IsEnabled = true;
     }
     else
     {
         _delConvBtn.Visibility = System.Windows.Visibility.Hidden;
         _inviteBtn.Visibility = System.Windows.Visibility.Hidden;
         _kickBtn.Visibility = System.Windows.Visibility.Hidden;
         _leaveBtn.Visibility = System.Windows.Visibility.Visible;
         _playBtn.IsEnabled = false;
     }
     if (mainWindow.Player.MainRoomId == Party.ConversationId)
         _mainRoomBtn.IsEnabled = false;
     else
         _mainRoomBtn.IsEnabled = true;
 }
コード例 #26
0
 public void BombSpawnReplicationEventHandler(ConversationDC conv, int BombPositionX, int BombPositionY)
 {
     Callback.SpawnBomb(conv, BombPositionX, BombPositionY);
 }
コード例 #27
0
 public void PlayerDeathReplicationEventHandler(ConversationDC conv, PlayerDC player)
 {
     Callback.KillPlayer(conv, player);
 }
コード例 #28
0
 public void CreateConversation(ConversationDC newConv)
 {
     using (var db = new BomberDbContext())
     {
         var q = (from p in db.Players
                  where p.PlayerId == newConv.Host.PlayerId
                  select p).ToList();
         var convMembersIds = from i in newConv.Participants
                              select i.PlayerId;
         var convMembers = (from p in db.Players
                            where convMembersIds.Contains(p.PlayerId)
                            select p);
         if (q.Count > 0)
         {
             var host = q.ElementAt(0);
             Conversation c = new Conversation()
             {
                 Host = host,
                 ConversationLog = ""
             };
             // discussion : add the host to c.Players or not? let's say no, for now...
             foreach (var p in convMembers)
             {
                 if (!c.Players.Contains(p))
                     c.Players.Add(p);
             }
             db.Conversations.AddObject(c);
             db.SaveChanges();
             var convDC = EntityContractTranslator.ConversationToConversationDC(c);
             var cm = new ConversationManager(convDC);
             Conversations.Add(convDC.ConversationId, cm);
             if (Sessions.Keys.Contains(host.PlayerId))
             {
                 var s = Sessions[host.PlayerId];
                 cm.EndOfConvEvent += s.EndOfConvEventHandler;
                 cm.JoinEvent += s.JoinConvEventHandler;
                 cm.KickEvent += s.KickFromConvEventHandler;
                 cm.LeaveEvent += s.LeaveConvEventHandler;
                 cm.MessageEvent += s.ConvMessageEventHandler;
                 s.Callback.InitializeConversation(convDC);
             }
             foreach (var p in convMembers)
             {
                 if (Sessions.Keys.Contains(p.PlayerId))
                 {
                     var s = Sessions[p.PlayerId];
                     cm.EndOfConvEvent += s.EndOfConvEventHandler;
                     cm.JoinEvent += s.JoinConvEventHandler;
                     cm.KickEvent += s.KickFromConvEventHandler;
                     cm.LeaveEvent += s.LeaveConvEventHandler;
                     cm.MessageEvent += s.ConvMessageEventHandler;
                     s.Callback.InitializeConversation(convDC);
                 }
             }
         }
     }
 }