internal void SendPieceSyncCommands
        (string matchId, string accountId, int playerSlot, GamePiece piece)
    {
        string cmd = string.Format("{0}{1}{2}{1}{3}{1}{4}{1}{5}{1}{6}{1}{7}{1}{8}{1}{9}{1}{10}{1}{11}{1}{12}{1}{13}{1}{14}",
                                   (int)ReadProtocol.GetVersion(),
                                   m_SegmentTerminator,
                                   NetworkCommand.GetCommand(NetworkCommandType.SyncGamePiece),
                                   matchId,
                                   accountId,
                                   playerSlot,
                                   piece.NetworkIdentity,
                                   piece.GamePieceName,
                                   piece.BoardVector.x,
                                   piece.BoardVector.y,
                                   piece.CurrentHitPoints,
                                   piece.DefenseRating,
                                   piece.AttackRating,
                                   piece.TurnDelay,
                                   (int)piece.gameObject.transform.rotation.eulerAngles.y);

        Debug.Log("Sending: " + cmd);

        SendData(cmd);

        cmd = string.Format("{0}{1}{2}{1}{3}{1}{4}",
                            (int)ReadProtocol.GetVersion(),
                            m_SegmentTerminator,
                            NetworkCommand.GetCommand(NetworkCommandType.EndGamePieceSync),
                            matchId,
                            accountId);

        Debug.Log("Sending: " + cmd);

        SendData(cmd);
    }
        private void HandleMatchEndEvent(string matchId)
        {
            string cmd = string.Format("{0}{1}{2}{1}{3}",
                                       (int)ReadProtocol.GetVersion(),
                                       m_SegmentTerminator,
                                       NetworkCommand.GetCommand(NetworkCommandType.EndMatch),
                                       matchId);

            ClientManager.SendMessageToAllClients(cmd);
        }
        private void HandleLobbyMessage_One(string id, string[] segments)
        {
            string cmd = string.Format("{0}{1}{2}{1}{3}{1}{4}{1}{5}",
                                       (int)ReadProtocol.GetVersion(),
                                       m_SegmentTerminator,
                                       NetworkCommand.GetCommand(NetworkCommandType.LobbyMessage),
                                       segments[2], segments[3], segments[4]);

            ClientManager.SendMessageToAllClients(cmd);
        }
    internal void AttemptLogin(string username, string password)
    {
        string cmd = string.Format("{0}{1}{2}{1}{3}{1}{4}",
                                   (int)ReadProtocol.GetVersion(), m_SegmentTerminator,
                                   NetworkCommand.GetCommand(NetworkCommandType.Login), username, password);

        Debug.Log("Sending: " + cmd);

        SendData(cmd);
    }
        private void HandleMatchJoinResult(ClientState client, string matchId, bool succeeeded)
        {
            string cmd = string.Format("{0}{1}{2}{1}{3}{1}{4}",
                                       (int)ReadProtocol.GetVersion(),
                                       m_SegmentTerminator,
                                       NetworkCommand.GetCommand(NetworkCommandType.JoinMatchResult),
                                       succeeeded.ToString(),
                                       matchId);

            client.SendData(cmd);
        }
        private void InterEventDispatcher_MatchStartEvent(MatchStartEventArgs args)
        {
            string cmd = string.Format("{0}{1}{2}{1}{3}{1}{4}",
                                       (int)ReadProtocol.GetVersion(),
                                       m_SegmentTerminator,
                                       NetworkCommand.GetCommand(NetworkCommandType.StartMatch),
                                       args.MatchId,
                                       args.PlayerIdOfFirstToMove);

            MatchHandler.SendMessageToUsersInMatch(args.MatchId, cmd);
        }
    internal void SendCirculationCommand()
    {
        string cmd = string.Format("{0}{1}{2}",
                                   (int)ReadProtocol.GetVersion(),
                                   m_SegmentTerminator,
                                   NetworkCommand.GetCommand(NetworkCommandType.Heartbeat));

        Debug.Log("Sending: " + cmd);

        SendData(cmd);
    }
    internal void SendLogoutNotification()
    {
        string cmd = string.Format("{0}{1}{2}",
                                   (int)ReadProtocol.GetVersion(),
                                   m_SegmentTerminator,
                                   NetworkCommand.GetCommand(NetworkCommandType.LogOut));

        Debug.Log("Sending: " + cmd);

        SendData(cmd);
    }
    internal void SendFriendRemovalNotification(Account account)
    {
        string cmd = string.Format("{0}{1}{2}{1}{3}",
                                   (int)ReadProtocol.GetVersion(),
                                   m_SegmentTerminator,
                                   NetworkCommand.GetCommand(NetworkCommandType.RemoveFriend),
                                   account.Identity);

        Debug.Log("Sending: " + cmd);

        SendData(cmd);
    }
示例#10
0
        private void NetworkEventDispatcher_ClientCirculationEvent(ClientCirculationEventArgs args)
        {
            string cmd = string.Format("{0}{1}{2}",
                                       (int)ReadProtocol.GetVersion(),
                                       m_SegmentTerminator,
                                       NetworkCommand.GetCommand(NetworkCommandType.Heartbeat));

            if (args.ClientState != null)
            {
                args.ClientState.SendData(cmd);
            }
        }
示例#11
0
        private void SendSpectatorDepartureNotification(string matchId, PlayerState spectator)
        {
            string cmd = string.Format("{0}{1}{2}{1}{3}{1}{4}{1}{5}",
                                       (int)ReadProtocol.GetVersion(),
                                       m_SegmentTerminator,
                                       NetworkCommand.GetCommand(NetworkCommandType.RemoveSpectator),
                                       matchId,
                                       spectator.AccountIdentity,
                                       spectator.Username);

            ClientManager.SendMessageToAllClients(cmd);
        }
示例#12
0
        private void MatchEventDispatcher_SpectatorSyncEvent(SpectatorSyncEventArgs args)
        {
            string cmd = string.Format("{0}{1}{2}{1}{3}{1}{4}{1}{5}",
                                       (int)ReadProtocol.GetVersion(),
                                       m_SegmentTerminator,
                                       NetworkCommand.GetCommand(NetworkCommandType.SyncMatchSpectator),
                                       args.Match.MatchIdentity,
                                       args.PlayerState.AccountIdentity,
                                       args.PlayerState.Username);

            MatchHandler.SendMessageToUsersInMatch(args.Match, cmd);
        }
示例#13
0
    internal void SendSpectateMatchCommand(string matchId)
    {
        //Protocol#|spcmtch#|matchId
        string cmd = string.Format("{0}{1}{2}{1}{3}",
                                   (int)ReadProtocol.GetVersion(),
                                   m_SegmentTerminator,
                                   NetworkCommand.GetCommand(NetworkCommandType.SpectateMatch),
                                   matchId);

        Debug.Log("Sending: " + cmd);

        SendData(cmd);
    }
示例#14
0
        private void InterEventDispatcher_TurnStateSyncEvent(TurnStateSyncEventArgs args)
        {
            string cmd = string.Format("{0}{1}{2}{1}{3}{1}{4}{1}{5}{1}{6}",
                                       (int)ReadProtocol.GetVersion(),
                                       m_SegmentTerminator,
                                       NetworkCommand.GetCommand(NetworkCommandType.TurnStateSync),
                                       args.MatchId,
                                       args.CurrentPlayerId,
                                       args.TurnStep.ToString(),
                                       args.LowestTurnStep.ToString());

            MatchHandler.SendMessageToUsersInMatch(args.MatchId, cmd);
        }
示例#15
0
    internal void SendTurnUpdateCommand(string matchId, int turnStep)
    {
        //protocol#|cmd#|matchId#|step
        string cmd = string.Format("{0}{1}{2}{1}{3}{1}{4}",
                                   (int)ReadProtocol.GetVersion(),
                                   m_SegmentTerminator,
                                   NetworkCommand.GetCommand(NetworkCommandType.TurnStateUpdate),
                                   matchId,
                                   turnStep.ToString());

        Debug.Log("Sending: " + cmd);

        SendData(cmd);
    }
示例#16
0
    internal void SendStartMatchCommand(Account account)
    {
        //protocol#|crtmtch#|userId#|username
        string cmd = string.Format("{0}{1}{2}{1}{3}{1}{4}",
                                   (int)ReadProtocol.GetVersion(),
                                   m_SegmentTerminator,
                                   NetworkCommand.GetCommand(NetworkCommandType.CreateMatch),
                                   account.Identity,
                                   account.Username);

        Debug.Log("Sending: " + cmd);

        SendData(cmd);
    }
示例#17
0
        private void InterEventDispatcher_AttackSyncCompleteEvent(AttackSyncCompleteEventArgs args)
        {
            string cmd = string.Format("{0}{1}{2}{1}{3}{1}{4}{1}{5}{1}{6}{1}{7}",
                                       (int)ReadProtocol.GetVersion(),
                                       m_SegmentTerminator,
                                       NetworkCommand.GetCommand(NetworkCommandType.ProcessAttack),
                                       args.MatchId,
                                       args.AttackingPieceId,
                                       args.DefendingPlayerId,
                                       args.BoardVectorX.ToString(),
                                       args.BoardVectorY.ToString());

            MatchHandler.SendMessageToUsersInMatch(args.MatchId, cmd);
        }
示例#18
0
        private void HandleMatchMessage_One(string[] segments)
        {
            //protocol#|lbymsg#|matchId#|username#|time#|message<#>
            string cmd = string.Format("{0}{1}{2}{1}{3}{1}{4}{1}{5}{1}{6}",
                                       (int)ReadProtocol.GetVersion(),
                                       m_SegmentTerminator,
                                       NetworkCommand.GetCommand(NetworkCommandType.MatchMessage),
                                       segments[2],
                                       segments[3],
                                       segments[4],
                                       segments[5]);

            MatchHandler.SendMessageToUsersInMatch(segments[2], cmd);
        }
示例#19
0
        private void NetworkEventDispatcher_AccountCreationSucessEvent(AccountCreationSuccessArgs args)
        {
            ClientState client = ClientManager.GetClientById(args.ClientId);

            if (client != null)
            {
                string s = (string.Format("{0}{1}{2}",
                                          (int)ReadProtocol.GetVersion(),
                                          m_SegmentTerminator,
                                          NetworkCommand.GetCommand(NetworkCommandType.AccountCreated)));

                client.SendData(s);
            }
        }
示例#20
0
        private void NetworkEventDispatcher_UserLoginEvent(UserLoginEventArgs args)
        {
            try
            {
                ClientState client = ClientManager.GetClientById(args.ClientId);
                if (client != null)
                {
                    if (args.Success)
                    {
                        Account account = new Account(args.ClientId, args.Username);
                        AccountHandler.AddOnlineAccount(account);

                        client.Authorize(account);

                        //0#|lgnsccs#|username#|email#|rating#|wins#|losses#|id
                        string s = string.Format("{0}{1}{2}{1}{3}{1}{4}{1}{5}{1}{6}{1}{7}{1}{8}",
                                                 (int)ReadProtocol.GetVersion(),
                                                 m_SegmentTerminator,
                                                 NetworkCommand.GetCommand(NetworkCommandType.LoginSuccess),
                                                 account.Username,
                                                 account.Email,
                                                 account.Rating,
                                                 account.Wins,
                                                 account.Losses,
                                                 account.AccountId);

                        client.SendData(s);

                        SendAllAccountSyncDataToClient(client, AccountSyncType.Connect);
                        SendAccountSyncDataToAllClients(account, client, AccountSyncType.Connect);

                        SyncUserFriends(account);
                        SyncAllAvailableMatchesWithClient(client);
                    }

                    else
                    {
                        string s = string.Format("{0}{1}{2}{1}{3}",
                                                 (int)ReadProtocol.GetVersion(),
                                                 m_SegmentTerminator,
                                                 NetworkCommand.GetCommand(NetworkCommandType.LoginFail),
                                                 args.LoggedIn.ToString());

                        client.SendData(s);
                    }
                }
            }

            catch (Exception e) { Console.WriteLine(e.ToString()); }
        }
示例#21
0
        private void SyncMatchSpectators(MatchState match)
        {
            foreach (PlayerState state in match.Spectators.Values.ToList())
            {
                string cmd = string.Format("{0}{1}{2}{1}{3}{1}{4}{1}{5}",
                                           (int)ReadProtocol.GetVersion(),
                                           m_SegmentTerminator,
                                           NetworkCommand.GetCommand(NetworkCommandType.SyncMatchSpectator),
                                           match.MatchIdentity,
                                           state.AccountIdentity,
                                           state.Username);

                ClientManager.SendMessageToAllClients(cmd);
            }
        }
示例#22
0
        private string GetFriendSyncCommand(Account account)
        {
            //protocol#|sncfrnd#|username#|rating#|wins#|losses#|id
            string cmd = string.Format("{0}{1}{2}{1}{3}{1}{4}{1}{5}{1}{6}{1}{7}",
                                       (int)ReadProtocol.GetVersion(),
                                       m_SegmentTerminator,
                                       NetworkCommand.GetCommand(NetworkCommandType.SyncFriend),
                                       account.Username,
                                       account.Rating,
                                       account.Wins,
                                       account.Losses,
                                       account.AccountId);

            return(cmd);
        }
示例#23
0
        private void HandleSpectatorJoinEvent(string matchId, string clientId, bool succeeded)
        {
            MatchState match = MatchHandler.GetMatchStateById(matchId);

            string cmd = string.Format("{0}{1}{2}{1}{3}{1}{4}",
                                       (int)ReadProtocol.GetVersion(),
                                       m_SegmentTerminator,
                                       NetworkCommand.GetCommand(NetworkCommandType.SpectateMatchResult),
                                       matchId,
                                       succeeded.ToString().ToLowerInvariant());

            ClientManager.GetClientById(clientId).SendData(cmd);

            SyncMatchSpectators(match);
        }
示例#24
0
    //protocol#|pvtmsg#|from#|to#|time#|message
    internal void SendPrivateMessage(string message, Account accountTo, Account accountFrom)
    {
        string cmd = string.Format("{0}{1}{2}{1}{3}{1}{4}{1}{5}{1}{6}",
                                   (int)ReadProtocol.GetVersion(),
                                   m_SegmentTerminator,
                                   NetworkCommand.GetCommand(NetworkCommandType.PrivateMessage),
                                   accountFrom.Identity,
                                   accountTo.Identity,
                                   DateTime.UtcNow.ToShortTimeString(),
                                   message);

        Debug.Log("Sending: " + cmd);

        SendData(cmd);
    }
示例#25
0
        private void HandlePrivateMessage_One(string[] segments)
        {
            //protocol#|pvtmsg#|from#|to#|time#|message
            string cmd = string.Format("{0}{1}{2}{1}{3}{1}{4}{1}{5}{1}{6}",
                                       (int)ReadProtocol.GetVersion(),
                                       m_SegmentTerminator,
                                       NetworkCommand.GetCommand(NetworkCommandType.PrivateMessage),
                                       segments[2],
                                       segments[3],
                                       segments[4],
                                       segments[5]);

            ClientManager.SendMessageToClientByAccount
                (AccountHandler.GetAccountById(segments[3]), cmd);
        }
示例#26
0
    //protocol#|lbymsg#|matchId#|username#|time#|message<#>
    internal void SendMatchMessage(string message, string matchId)
    {
        string cmd = string.Format("{0}{1}{2}{1}{3}{1}{4}{1}{5}{1}{6}",
                                   (int)ReadProtocol.GetVersion(),
                                   m_SegmentTerminator,
                                   NetworkCommand.GetCommand(NetworkCommandType.MatchMessage),
                                   matchId,
                                   AccountManager.AccountInstance.Username,
                                   DateTime.UtcNow.ToShortTimeString(),
                                   message);

        Debug.Log("Sending: " + cmd);

        SendData(cmd);
    }
示例#27
0
        private void HandleNetworkPieceMove_One(string[] segments)
        {
            //protocol#|command#|matchId#|pieceNetId#|x#|y

            string cmd = string.Format("{0}{1}{2}{1}{3}{1}{4}{1}{5}{1}{6}",
                                       (int)ReadProtocol.GetVersion(),
                                       m_SegmentTerminator,
                                       NetworkCommand.GetCommand(NetworkCommandType.NetworkPieceMoveEvent),
                                       segments[2],
                                       segments[3],
                                       segments[4],
                                       segments[5]);

            MatchHandler.SendMessageToUsersInMatch(segments[2], cmd);
        }
示例#28
0
    //protocol#|crtacct#|username#|password#|email<#>
    internal void RequestNewAccount(string username, string password, string email)
    {
        string cmd = string.Format("{0}{1}{2}{1}{3}{1}{4}{1}{5}",
                                   (int)ReadProtocol.GetVersion(),

                                   m_SegmentTerminator,

                                   NetworkCommand.GetCommand(NetworkCommandType.CreateAccount),

                                   username, password, email);

        Debug.Log("Sending: " + cmd);

        SendData(cmd);
    }
示例#29
0
        private string GetMatchSyncCommand(MatchState match)
        {
            //protocol#|mtchcrtd#|matchId#|playerOneId#|playerOneUsername#|playerTwoId#|playerTwoUsername
            string cmd = string.Format("{0}{1}{2}{1}{3}{1}{4}{1}{5}{1}{6}{1}{7}{1}{8}",
                                       (int)ReadProtocol.GetVersion(),
                                       m_SegmentTerminator,
                                       NetworkCommand.GetCommand(NetworkCommandType.SyncMatchParticipants),
                                       match.MatchIdentity,
                                       match.PlayerOne != null ? match.PlayerOne.AccountIdentity : "-1",
                                       match.PlayerOne != null ? match.PlayerOne.Username : "******",
                                       match.PlayerTwo != null ? match.PlayerTwo.AccountIdentity : "-1",
                                       match.PlayerTwo != null ? match.PlayerTwo.Username : "******",
                                       match.InProgress.ToString());

            return(cmd);
        }
示例#30
0
        private string GetAccountSyncCommand(Account account, AccountSyncType syncType)
        {
            //protocol#|syncfacct#|syncType#|username#|rating#|wins#|losses<#>
            string cmd = string.Format("{0}{1}{2}{1}{3}{1}{4}{1}{5}{1}{6}{1}{7}{1}{8}",
                                       (int)ReadProtocol.GetVersion(),
                                       m_SegmentTerminator,
                                       NetworkCommand.GetCommand(NetworkCommandType.SyncForeignAccount),
                                       (int)syncType,
                                       account.Username,
                                       account.Rating,
                                       account.Wins,
                                       account.Losses,
                                       account.AccountId);

            return(cmd);
        }