public static Interfaces.IOtherPlayerData TranslatePlayerInfoToPlayerOtherData(Packets.PlayerInfo from)
        {
            Usefull.PlayerData to = new UDPClientServerCommons.Usefull.PlayerData();

            to.PlayerId = from.PlayerId;
            to.Timestamp = from.Timestamp;
            to.LookingDirection = TranslateBetweenVectorAndVector(from.PlayerLookingDirection);
            to.Position = TranslateBetweenVectorAndVector(from.PlayerPosition);
            to.Velocity = TranslateBetweenVectorAndVector(from.PlayerMovementDirection);
            if (from.PlayerCarringWeponOne)
                to.Weapon = UDPClientServerCommons.Constants.WeaponEnumeration.CrossBow;
            else if (from.PlayerCarringWeponTwo)
                to.Weapon = UDPClientServerCommons.Constants.WeaponEnumeration.Sword;
            else
                to.Weapon = UDPClientServerCommons.Constants.WeaponEnumeration.None;

            return (Interfaces.IOtherPlayerData)to;
        }
Exemple #2
0
        static void Main(string[] args)
        {
            //Console.WriteLine("How do you want to start Server?");
            // Console.WriteLine("[1]\t by passing port number (ex. 1234)");
            // Console.WriteLine("[2]\t by passing Ip Adress and port number (ex. 127.0.0.1:1234)");
            // Console.WriteLine("[3]\t Default");
            // string input = Console.ReadLine();
            try
            {
                timer = new System.Threading.Timer(new System.Threading.TimerCallback(timerCallback), null, 1000, 1000);
                CS_Server = new ServerSide(1234);
                CS_Server.MessageWasReceivedEvent += new EventHandler(CS_Server_MessageWasReceivedEvent);
                GameOptions gameOptions = new GameOptions("Poland", "Niemcy", UDPClientServerCommons.Constants.GameTypeEnumeration.FragLimit, 10);
                //IPEndPoint adress = CS_Server.StartLANServer(gameOptions,true,null);

                IPEndPoint adress = CS_Server.StartLANServer(gameOptions, false, new UDPClientServerCommons.Usefull.PlayerMe("Poland", "ServerPlayer"));

                Console.WriteLine("Server started at adress : {0}", adress.ToString());
                Console.WriteLine("Press [ENTER] to termiante...");
                Console.Title = "Castle Strike Server - Press [ENTER] to termiante...";
                while (true)
                {
                    string input = Console.ReadLine();
                    if (input.ToLower() == "start")
                        Console.WriteLine(" Trying to start game .... Started? {0}", CS_Server.StartGame());
                    if (input.ToLower() == "info")
                    {
                        if (CS_Server.Client.CurrentGameInfo != null)
                            Console.WriteLine(CS_Server.Client.CurrentGameInfo.ToString());
                    }
                    if (input.ToLower() == "pl")
                    {
                        List<UDPClientServerCommons.Interfaces.IOtherPlayerData> list = new List<UDPClientServerCommons.Interfaces.IOtherPlayerData>(CS_Server.Client.PlayerDataList);
                        for (int i = 0; i < list.Count; i++)
                            Console.WriteLine("\t {0}", list[i]);
                    }
                    if (input.ToLower() == "jump")
                    {
                        UDPClientServerCommons.Interfaces.IPlayerDataWrite pd = new UDPClientServerCommons.Usefull.PlayerData();
                        pd.Jump = true;
                        pd.Weapon = UDPClientServerCommons.Constants.WeaponEnumeration.CrossBow;

                        CS_Server.Client.UpdatePlayerData(pd);
                    }
                    if (input.ToLower() == "shoot")
                    {
                        UDPClientServerCommons.Interfaces.IPlayerDataWrite pd = new UDPClientServerCommons.Usefull.PlayerData();
                        pd.Shoot = true;
                        pd.Weapon = UDPClientServerCommons.Constants.WeaponEnumeration.CrossBow;

                        CS_Server.Client.UpdatePlayerData(pd);
                    }
                    if (input.ToLower() == "team")
                    {
                        List<UDPClientServerCommons.Usefull.TeamData> tdList = new List<UDPClientServerCommons.Usefull.TeamData>();
                        tdList.Add(new UDPClientServerCommons.Usefull.TeamData(13,null));
                        tdList[0].TeamScore= teamScore;
                        teamScore++;
                        CS_Server.UpdatePlayerHealthAndTeamScore(null, tdList);
                    }
                    if (input.Length == 0)
                        break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                if (CS_Server != null)
                CS_Server.Dispose();
            }
        }
        private void timerCallback(object obj)
        {
            try
            {
                UDPClientServerCommons.Interfaces.IPlayerDataWrite pdata = new UDPClientServerCommons.Usefull.PlayerData();

                    float valX = (float)( txtX.Invoke(new GetVal(getValueFromTxtX)));
                    float valY = (float)(txtY.Invoke(new GetVal(getValueFromTxtY)));

                    pdata.Position = new Microsoft.DirectX.Vector3(valX, valY, 0.0f);
                    pdata.LookingDirection = new Microsoft.DirectX.Vector3(valX, valY, 0.0f);
                    pdata.Velocity = new Microsoft.DirectX.Vector3(valX, valY, 0.0f);

                    lock (cordsLock)
                    {
                        pdata.Jump = jumpField;
                        pdata.Shoot = shootField;
                        if (jumpField)
                            jumpField = false;
                        if (shootField)
                            shootField = false;
                    }
                    network.UpdatePlayerData(pdata);

                dgData.Invoke(new RefreshStuff(RefreshGrid), network.PlayerDataList);
                List<UDPClientServerCommons.Interfaces.IGameEvent> gevent = network.GameEventList;
                List<UDPClientServerCommons.Interfaces.IGameplayEvent> gpevent = network.GameplayEventList;
                txtEvents.Invoke(new RefreshStuff(RefreshGameEvents), gevent);
                txtEvents.Invoke(new RefreshStuff(RefreshGameplayEvents), gpevent);
                txtSend.Invoke(new ShowData(showData), pdata);
            }
            catch (Exception ex)
            {
                UDPClientServerCommons.Diagnostic.NetworkingDiagnostics.Logging.Error(" client timerCallback Error", ex);
            }
        }