Пример #1
0
        public SecondarySoundBuffer loadSound(string filename)
        {
            SecondarySoundBuffer s = null;

            System.Diagnostics.Trace.WriteLine("Loading sound " + filename);
            if (isAI && !autoPlayTarget)
            {
                if (!forceStareo)
                {
                    s = DSound.LoadSound3d(filename);
                }
                else
                {
                    s = DSound.LoadSound(filename);
                }
            }
            else             //Either this is not AI or this is autoPlayTarget
            {
                s = DSound.LoadSound(filename);
            }
            if (s == null)
            {
                System.Diagnostics.Trace.WriteLine(filename + " is a null buffer");
            }
            return(s);
        }
Пример #2
0
 public virtual void onTick()
 {
     //First, need to set what object sare in range
     //since this is the first ontick method.
     if (vArray == null)
     {
         vArray = Interaction.getObjectsInRange(this,
                                                reachRange,
                                                Interaction.RangeFlag.existing);
     }
     updateTotalDistance();
     move();
     if (Options.mode == Options.Modes.mission &&
         followTarget &&
         origTarget != null)
     {
         z = origTarget.z;
     }
     if (damage < 1)
     {
         expl = DSound.LoadSound(DSound.SoundPath + "\\m4-1.wav");
         DSound.PlaySound(expl, true, false);
         finished = true;
     }
 }
Пример #3
0
 private void playTaunt(String t)
 {
     if (taunt != null && DSound.isPlaying(taunt))
     {
         return;
     }
     taunt = DSound.LoadSound(t);
     DSound.PlaySound(taunt, true, false);
 }
Пример #4
0
 public ExplosiveMissile(Weapons w)
     : base(w, "p" + (int)WeaponTypes.explosiveMissile)
 {
     weapon.decreaseAmmunitionFor(WeaponTypes.explosiveMissile);
     missileLaunchSound = loadSound(soundPath + "m1.wav");
     missileSound       = DSound.LoadSound(DSound.SoundPath + "\\m2.wav");
     neutralizeSpeed(1500f);
     setSpan(0.1f, 0.1f);
     followTarget = false;
 }
Пример #5
0
 public SAMMissile(Weapons w)
     : base(w, "p" + (int)WeaponTypes.samMissile)
 {
     weapon.decreaseAmmunitionFor(WeaponTypes.samMissile);
     neutralizeSpeed(3000f);
     launch    = loadSound(soundPath + "sam1.wav");
     moveSound = DSound.LoadSound(DSound.SoundPath + "\\bsg2.wav");
     setSpan(0.20f, 0.20f);
     followTarget = false;
 }
Пример #6
0
 public CruiseMissile(Weapons w)
     : base(w, "p" + (int)WeaponTypes.cruiseMissile)
 {
     type = WeaponTypes.cruiseMissile;
     weapon.decreaseAmmunitionFor(WeaponTypes.cruiseMissile);
     neutralizeSpeed((weapon.creator.flyingCruiseMissile) ? 1800f : 900f);
     setSpan(0.10f, 0.25f);
     launchSound  = loadSound(soundPath + "cr1.wav");
     missileSound = DSound.LoadSound(DSound.SoundPath + "\\cr2.wav");
 }
Пример #7
0
 public MissileInterceptor(Weapons w)
     : base(w, "p" + (int)WeaponTypes.cruiseMissile)
 {
     type = WeaponTypes.missileInterceptor;
     weapon.decreaseAmmunitionFor(WeaponTypes.missileInterceptor);
     neutralizeSpeed(900f);
     setSpan(0.10f, 0.25f);
     launchSound  = loadSound(soundPath + "ci1.wav");
     missileSound = DSound.LoadSound(DSound.SoundPath + "\\ci2.wav");
 }
Пример #8
0
 public Missile(Weapons w)
     : base(w, "p" + (int)WeaponTypes.missile)
 {
     type = WeaponTypes.missile;
     weapon.decreaseAmmunitionFor(WeaponTypes.missile);
     missileLaunchSound = loadSound(soundPath + "m1.wav");
     missileSound       = DSound.LoadSound(DSound.SoundPath + "\\m2.wav");
     neutralizeSpeed(1500f);
     setSpan(0.1f, 0.1f);
 }
 public BattleShipGuns(Weapons w)
     : base(w, "p" + (int)WeaponTypes.battleShipGuns)
 {
     weapon.decreaseAmmunitionFor(WeaponTypes.battleShipGuns);
     neutralizeSpeed(1000f);
     launch    = loadSound(soundPath + "bsg1.wav");
     moveSound = DSound.LoadSound(DSound.SoundPath + "\\bsg2.wav");
     setSpan(0.05f, 0.10f);
     followTarget = false;
     explodes     = (Common.getRandom(0, 1) == 0) ? false : true;
 }
Пример #10
0
        protected SecondarySoundBuffer loadSound(string filename)
        {
            SecondarySoundBuffer s = null;

            if (isAI)
            {
                s = DSound.LoadSound3d(DSound.SoundPath + "\\a_" + filename);
            }
            else
            {
                s = DSound.LoadSound(DSound.SoundPath + "\\" + filename);
            }
            return(s);
        }
Пример #11
0
        protected void explode()
        {
            expl = DSound.LoadSound(DSound.SoundPath + "\\m4-1.wav");
            playSound3d(expl, true, false);
            List <Projector> hits = Interaction.getObjectsInRange(this, new Range(2f, 1000f), Interaction.RangeFlag.existing);

            if (hits == null)
            {
                return;
            }
            foreach (Projector hit in hits)
            {
                fireHitEvent(hit, 10);
            }
        }
Пример #12
0
 private void playMessage(String o, bool wait)
 {
     if (message != null)
     {
         message.Stop();
     }
     message = DSound.LoadSound(o);
     DSound.PlaySound(message, true, false);
     if (wait)
     {
         Interaction.stopAndMute(true);
         while (DSound.isPlaying(message))
         {
             Thread.Sleep(100);
         }
         Interaction.resumeAndUnmute();
     }             //if wait
 }
        public override void onTick()
        {
            if (isFinished())
            {
                fireDisposeEvent();
                return;
            }
            if (finished && performing)
            {
                //The weapon is done doing what it needs to do, but a sound is still playing.
                //Do not free this weapon until the sound is done playing .
                performing = (Hit != null && DSound.isPlaying(Hit)) || (expl != null && DSound.isPlaying(expl));
                return;
            }

            performing = true;
            base.onTick();
            playSound(moveSound, false, false);
            if (inFiringRange())
            {
                moveSound.stop();
                if (explodes)
                {
                    Hit = DSound.LoadSound(DSound.SoundPath + "\\m4-1.wav");
                    playSound3d(Hit, true, false);
                }
                else
                {
                    Hit = target.loadSound(target.soundPath + "bsg" + Common.getRandom(3, 4) + ".wav");
                    target.playSound(Hit, true, false);
                }
                fireHitEvent(target, (explodes) ? Common.getRandom(250, 300) : Common.getRandom(201, 250));
                finished = true;
                return;
            }

            if (!DSound.isPlaying(moveSound))
            {
                finished = true;
                explode();
                performing = (Hit != null && DSound.isPlaying(Hit)) || (expl != null && DSound.isPlaying(expl));
            }
        }
Пример #14
0
        public SecondarySoundBuffer loadSound(string filename)
        {
            SecondarySoundBuffer s = null;

            if (isAI && !autoPlayTarget)
            {
                if (!forceStareo)
                {
                    s = DSound.LoadSound3d(filename);
                }
                else
                {
                    s = DSound.LoadSound(filename);
                }
            }
            else             //Either this is not AI or this is autoPlayTarget
            {
                s = DSound.LoadSound(filename);
            }
            return(s);
        }
Пример #15
0
        public ExtendedAudioBuffer loadSound(string filename, bool notifications, bool alwaysLoud)
        {
            ExtendedAudioBuffer s = null;

            if (isAI && !autoPlayTarget)
            {
                if (!forceStareo)
                {
                    s = (!alwaysLoud)? DSound.LoadSound(filename, notifications): DSound.LoadSoundAlwaysLoud(filename, notifications);
                }
                else
                {
                    s = (!alwaysLoud)? DSound.LoadSound(filename, notifications): DSound.LoadSoundAlwaysLoud(filename, notifications);
                }
            }
            else             //Either this is not AI or this is autoPlayTarget
            {
                s = (!alwaysLoud) ? DSound.LoadSound(filename, notifications) : DSound.LoadSoundAlwaysLoud(filename, notifications);
            }
            return(s);
        }
Пример #16
0
        public static void NLS(string sFilename, bool NWait, long TheRate)
        {
            try
            {
                stopLastFile();
                filesPlaying = true;
                files        = new StringBuilder();
                String[] SFiles = sFilename.Split('&');
                for (int i = 0; i < SFiles.Length; i++)
                {
                    sFilename = SFiles[i];
                    //if # is in front of array element author wants that element to be num voiced,
                    //and it is not a .wav file.
                    if (sFilename.Contains("#"))
                    {
                        processNumber(
                            sFilename.Substring(
                                sFilename.IndexOf("#") + 1
                                ));
                    }
                    else
                    {
                        //if reg .wav file
                        sFilename = processFileName(sFilename);
                        files.Append(sFilename);
                        if (i != SFiles.Length - 1)
                        {
                            files.Append("&");
                        }
                    }             //if not number
                }                 //loop

                //Now we have all the files to play.
                String[] finalFiles = files.ToString().Split(new char[] { '&' }, StringSplitOptions.RemoveEmptyEntries);
                soundFiles = new SecondarySoundBuffer[finalFiles.Length];
                bool firstLoop = true;
                for (globalCounter = 0; globalCounter < soundFiles.Length; globalCounter++)
                {
                    if (firstLoop)
                    {
                        soundFiles[globalCounter] = DSound.LoadSound(finalFiles[globalCounter]);
                    }
                    DSound.PlaySound(soundFiles[globalCounter], true, false);
                    if (globalCounter < finalFiles.Length - 1)
                    {
                        soundFiles[globalCounter + 1] = DSound.LoadSound(finalFiles[globalCounter + 1]);
                    }
                    firstLoop = false;
                    //Next, if only playing one file, return since we're probably in a menu.
                    if (soundFiles.Length != 1 || NWait)
                    {
                        NumWait();
                    }

                    if (nStop)
                    {
                        filesPlaying = false;
                        return;
                    }
                }

                //next, global counter may be == length
                //of array since we completed the loop
                //so back it up to stop properly.
                if (globalCounter == soundFiles.Length)
                {
                    globalCounter--;
                }
                filesPlaying = false;
            }
            catch (Exception e)
            {
                Common.handleError(e);
            }
        }
Пример #17
0
        private static void processRCV()
        {
            try
            {
                while (live)
                {
                    if (!CSCommon.isLiveConnection(client))
                    {
                        live = false;
                        SapiSpeech.speak("Error: Server crash.", SapiSpeech.SpeakFlag.noInterrupt);
                        Common.exitMenus = true;
                        Common.repop();
                        return;
                    }
                    MemoryStream stream = null;
                    //Bytes have to be explicitly copied into new stream since cmds is closed to save memory later on, so we'll lose rcvPauseData.
                    stream = CSCommon.getData(client);
                    BinaryReader cmds = null;
                    if (stream != null)
                    {
                        cmds = new BinaryReader(stream);
                    }
                    if (cmds != null)
                    {
                        sbyte t;
                        long  start = 0;                        //start position of current packet
                        while (cmds.BaseStream.Length > cmds.BaseStream.Position)
                        {
                            start = cmds.BaseStream.Position;
                            System.Diagnostics.Trace.WriteLine(String.Format("S: {0}, L: {1}", start, cmds.BaseStream.Length));
                            t = cmds.ReadSByte();
                            if (t == 1)
                            {
                                byte command = cmds.ReadByte();
                                System.Diagnostics.Trace.WriteLine("co " + command);
                                switch (command)
                                {
                                case CSCommon.cmd_addMember:
                                    addMember(cmds.ReadString(), cmds.ReadString());
                                    break;

                                case CSCommon.cmd_removeMember:
                                    removeMember(cmds.ReadString());
                                    break;

                                case CSCommon.cmd_resp:
                                    int respLength = cmds.ReadInt32();
                                    responseStream = new byte[respLength];
                                    cmds.BaseStream.Read(responseStream, 0, respLength);
                                    waitingForResponse.Set();
                                    break;

                                case CSCommon.cmd_notifyDemo:
                                    DSound.PlaySound(DSound.LoadSound(DSound.NSoundPath + "\\cd3.wav"), true, false);
                                    break;

                                case CSCommon.cmd_newval:
                                    SelfVoice.purge(true);
                                    int amount = cmds.ReadInt32();
                                    SelfVoice.NLS("#" + amount + "&points.wav", true, true);
                                    addChatMessage(String.Format("You earned {0} point{1}", amount, (amount == 1) ? "" : "s"));
                                    break;

                                case CSCommon.cmd_position:
                                    next   = cmds.ReadInt64();
                                    addOns = processAddOns(cmds);
                                    break;

                                case CSCommon.cmd_chat:
                                    MessageType type = (MessageType)cmds.ReadByte();
                                    if (type == MessageType.normal)
                                    {
                                        DSound.PlaySound(chatSound, true, false);
                                    }
                                    else if (type == MessageType.enterRoom)
                                    {
                                        DSound.PlaySound(chatEnterSound, true, false);
                                    }
                                    else if (type == MessageType.leaveRoom)
                                    {
                                        DSound.PlaySound(chatLeaveSound, true, false);
                                    }
                                    else if (type == MessageType.privateMessage)
                                    {
                                        DSound.PlaySound(privateMessageSound, true, false);
                                    }
                                    else
                                    {
                                        DSound.PlaySound(serverMessageSound, true, false);
                                    }
                                    String incomingChatMessage = cmds.ReadString();
                                    SapiSpeech.speak(incomingChatMessage, SapiSpeech.SpeakFlag.interruptable);
                                    addChatMessage(incomingChatMessage);
                                    Common.mainGUI.addToHistory(incomingChatMessage);
                                    break;

                                case CSCommon.cmd_serverMessage:
                                    String incomingServerMessage = cmds.ReadString();
                                    SapiSpeech.speak(incomingServerMessage, SapiSpeech.SpeakFlag.interruptable);
                                    addChatMessage(incomingServerMessage);
                                    break;

                                case CSCommon.cmd_forceDisconnect:                                         //Player was disconnected from the server
                                    //By the server itself and not through an in-game event,
                                    //so if we receive this command, we are being told to wipe our copy of the player in question.
                                    //Still, the server will send forceDisconnect even if object has already been disconnected
                                    //due to in-game event. This is ok since if the object is already gone,
                                    //this command will do nothing. It is just a redundancy check, more or less.
                                    String    idToTerminate = cmds.ReadString();
                                    Projector pToTerm       = Interaction.objectAt(idToTerminate);
                                    if (pToTerm != null)
                                    {
                                        pToTerm.requestingTerminate();
                                    }
                                    Interaction.clearLocks(idToTerminate);
                                    break;

                                case CSCommon.cmd_requestCreate:                                         //Response from server for requestCreate command sent by client.
                                    Interaction.createPlayer(cmds.ReadString(), cmds.ReadInt32());
                                    addSender(Mission.player.id);
                                    if (addOns != null)
                                    {
                                        Mission.player.setAddOns(addOns);
                                    }
                                    addOns = null;
                                    if (Options.mode == Options.Modes.teamDeath)
                                    {
                                        Mission.player.team = Options.team;
                                    }
                                    Interaction.startMultiplayerGame();
                                    break;

                                case CSCommon.cmd_distributeServerTag:
                                    Projector o = Interaction.createObjectFromServer(cmds.ReadString(), cmds.ReadString(), OnlineRole.receiver, (ObjectType)cmds.ReadByte());
                                    System.Diagnostics.Trace.WriteLine("Received request to create opponent " + o.name);
                                    if (Options.mode == Options.Modes.teamDeath)
                                    {
                                        o.team = (Projector.TeamColors)cmds.ReadInt32();
                                    }
                                    AddOnArgs[] distAdd = processAddOns(cmds);
                                    if (distAdd != null)
                                    {
                                        o.setAddOns(distAdd);
                                    }
                                    break;

                                case CSCommon.cmd_createBot:
                                    String    createBotId   = cmds.ReadString();
                                    String    createBotName = cmds.ReadString();
                                    Projector bot           = Interaction.createObjectFromServer(createBotId, createBotName, OnlineRole.bot, (ObjectType)cmds.ReadByte());                                   //will create bot or update current receiver to bot status.
                                    addSender(bot.id);
                                    break;

                                case CSCommon.cmd_startGame:
                                    hostStartedGame = true;

                                    System.Diagnostics.Trace.WriteLine("Host started game");
                                    break;

                                case CSCommon.cmd_gameEnded:
                                    Options.serverEndedGame = true;
                                    break;
                                }                                 //switch
                                System.Diagnostics.Trace.WriteLine("Command: " + t);
                                continue;
                            }                             //if command

                            System.Diagnostics.Trace.Write(String.Format("Stream position: {0}, start: {1}, Char: {2} ", (int)cmds.BaseStream.Position, start, t));
                            int size = cmds.ReadInt32();                             //total update size
                            System.Diagnostics.Trace.WriteLine("Size: " + size);
                            int    temSize = size;
                            String tag     = cmds.ReadString();
                            System.Diagnostics.Trace.WriteLine(tag + " queuing data...");
                            Projector p = null;
                            size = size - (int)(cmds.BaseStream.Position - start);
                            byte[] buffer = null;
                            try
                            {
                                buffer = new byte[size];
                            }
                            catch (OverflowException)
                            {
                                throw new OverflowException(String.Format("Size: {0}, Stream position: {1}, start: {2}, original size: {3} Char: {4}", size, (int)cmds.BaseStream.Position, start, temSize, t));
                            }
                            cmds.BaseStream.Read(buffer, 0, size);

                            //Object could have been deleted by the time this command is reached
                            if ((p = Interaction.objectAt(tag)) != null)
                            {
                                System.Diagnostics.Trace.WriteLine("Object found. sending queue");
                                p.queueData(t, buffer);
                            }                             //if object exists
                            else
                            {
                                System.Diagnostics.Trace.WriteLine("Object not found.");
                            }
                        }         //while more data to read
                        cmds.Close();
                    }             //if got data
                    Thread.Sleep(50);
                }                 //while live connection
            }
            catch (Exception e)
            {
                Common.handleError(e);
            }             //catch
            finally
            {
                releaseConnection();
            }
        }
Пример #18
0
        public static bool connect(String host, String callSign, int port)
        {
            ports = new int[] { 4444, 4445, 4567, 6969, 32000 };
            if (dataLocker == null)
            {
                dataLocker = new object();
            }
            if (chatLocker == null)
            {
                chatLocker = new object();
            }
            if (chatMessages == null)
            {
                chatMessages = new List <String>();
            }
            if (members == null)
            {
                members = new List <ChatRoomMember>();
            }
            chatPointer         = 0;
            chatSound           = DSound.LoadSound(DSound.SoundPath + "\\chat1.wav");
            chatEnterSound      = DSound.LoadSound(DSound.SoundPath + "\\chat2.wav");
            chatLeaveSound      = DSound.LoadSound(DSound.SoundPath + "\\chat3.wav");
            privateMessageSound = DSound.LoadSound(DSound.SoundPath + "\\chat4.wav");
            serverMessageSound  = DSound.LoadSound(DSound.SoundPath + "\\chat5.wav");
            senders             = new Dictionary <string, ClientRecord>();
            waitingForResponse  = new AutoResetEvent(false);
            isConnected         = false; error = false;
            live   = false;
            client = new TcpClient();
            int i    = (port != 0) ? Array.IndexOf(ports, port) : 0;
            int time = 0;

            while (i < ports.Length)
            {
                error = false;
                time  = 0;
                client.BeginConnect(host, port = ports[i++],
                                    new AsyncCallback(connectedEvent), null);
                while (!isConnected && !error)
                {
                    Application.DoEvents();
                    if (time >= 3000)
                    {
                        endConnect();                         //stop trying to connect on this port
                        break;
                    }
                    time += 100;
                    Thread.Sleep(100);
                }
                if (isConnected)
                {
                    break;
                }
            }             //search ports
            if (!isConnected || error)
            {
                return(false);
            }
            Options.writeToFile();
            try
            {
                using (BinaryWriter writer = new BinaryWriter(new MemoryStream()))
                {
                    writer.Write(callSign);
                    writer.Flush();
                    CSCommon.sendData(client, writer);
                }                 //using
                LoginMessages resp = LoginMessages.none;
                using (BinaryReader reader = new BinaryReader(CSCommon.getData(client, 5000)))
                {
                    resp       = (LoginMessages)reader.ReadInt32();
                    m_messages = resp;
                    if ((resp & LoginMessages.serverAssignedTag) == LoginMessages.serverAssignedTag)
                    {
                        serverTag = reader.ReadString();
                        String messageOfTheDay = reader.ReadString();
                        if ((resp & LoginMessages.messageOfTheDay) == LoginMessages.messageOfTheDay)
                        {
                            // We now need to speak the message and then show an input box for the user to
                            // press ENTER to continue. This is because some screen readers
                            // Don't have a way to stop the running thread.
                            SapiSpeech.speak("[Welcome message]: " + messageOfTheDay + " (press ENTER to continue)", SapiSpeech.SpeakFlag.interruptable);
                            Common.mainGUI.receiveInput().Trim();
                        }
                        System.Diagnostics.Trace.WriteLine("Server sent tag: " + serverTag);
                    }
                }                 //using
                if ((resp & LoginMessages.demo) == LoginMessages.demo)
                {
                    BPCSharedComponent.ExtendedAudio.DSound.playAndWait(BPCSharedComponent.ExtendedAudio.DSound.NSoundPath + "\\cd" + Common.getRandom(1, 2) + ".wav");
                }
                if ((resp & LoginMessages.noCallSign) == LoginMessages.noCallSign)
                {
                    BPCSharedComponent.ExtendedAudio.DSound.playAndWait(BPCSharedComponent.ExtendedAudio.DSound.NSoundPath + "\\ncs.wav");
                }
                if ((resp & LoginMessages.badVersion) == LoginMessages.badVersion)
                {
                    SapiSpeech.speak("There is a newer version of TDV available. Please update before logging on.", SapiSpeech.SpeakFlag.noInterrupt);
                    return(false);
                }
                if ((resp & LoginMessages.wrongCredentials) == LoginMessages.wrongCredentials)
                {
                    BPCSharedComponent.ExtendedAudio.DSound.playAndWait(BPCSharedComponent.ExtendedAudio.DSound.NSoundPath + "\\pw2.wav");
                    return(false);
                }
            }
            catch (IOException)
            {
                error = true;
            }
            catch (TimeoutException)
            {
                error = true;
            }
            if (error)
            {
                return(false);
            }

            if (log)
            {
                theFile = new StreamWriter(Addendums.File.appPath + "\\server_output.log");
            }
            live          = true;
            processThread = new Thread(processRCV);
            processThread.Start();
            return(true);
        }
Пример #19
0
        public static bool connect(String host, String password, int port, String tag)
        {
            System.Diagnostics.Trace.WriteLine("Server tag is " + tag);
            //	  ports = new int[]{4444, 4445, 4567, 6969, 32000 };
            ports = new int[] { 31111 };
            if (dataLocker == null)
            {
                dataLocker = new object();
            }
            if (chatLocker == null)
            {
                chatLocker = new object();
            }
            if (chatMessages == null)
            {
                chatMessages = new List <String>();
            }
            if (members == null)
            {
                members = new List <ChatRoomMember>();
            }
            chatPointer         = 0;
            chatSound           = DSound.LoadSound(DSound.SoundPath + "\\chat1.wav");
            chatEnterSound      = DSound.LoadSound(DSound.SoundPath + "\\chat2.wav");
            chatLeaveSound      = DSound.LoadSound(DSound.SoundPath + "\\chat3.wav");
            privateMessageSound = DSound.LoadSound(DSound.SoundPath + "\\chat4.wav");
            serverMessageSound  = DSound.LoadSound(DSound.SoundPath + "\\chat5.wav");
            senders             = new Dictionary <string, ClientRecord>();
            waitingForResponse  = new AutoResetEvent(false);
            isConnected         = false; error = false;
            live      = false;
            client    = new TcpClient();
            serverTag = tag;
            int i    = (port != 0) ? Array.IndexOf(ports, port) : 0;
            int time = 0;

            while (i < ports.Length)
            {
                error = false;
                time  = 0;
                client.BeginConnect(host, port = ports[i++],
                                    new AsyncCallback(connectedEvent), null);
                while (!isConnected && !error)
                {
                    Application.DoEvents();
                    if (time >= 3000)
                    {
                        endConnect();                         //stop trying to connect on this port
                        break;
                    }
                    time += 100;
                    Thread.Sleep(100);
                }
                if (isConnected)
                {
                    break;
                }
            }             //search ports
            if (!isConnected || error)
            {
                return(false);
            }
            Options.writeToFile();
            try
            {
                SslStream ssl = null;
                using (BinaryWriter writer = new BinaryWriter(new MemoryStream()))
                {
                    writer.Write((int)0);
                    System.Diagnostics.Trace.WriteLine("After int: " + writer.BaseStream.Length);
                    writer.Write(Convert.ToSingle(Common.applicationVersion));
                    writer.Write(tag);
                    System.Diagnostics.Trace.WriteLine("Tag is now " + tag);
                    if (password != null)
                    {
                        writer.Write(password);
                    }
                    writer.Flush();
                    System.Diagnostics.Trace.WriteLine("After password: "******"bpcprograms.com");
                    writer.BaseStream.Position = 0;
                    writer.Write((int)(writer.BaseStream.Length - 4));
                    writer.Flush();

                    System.Diagnostics.Trace.WriteLine("After data size print " + writer.BaseStream.Length);
                    System.Diagnostics.Trace.WriteLine("SSL packet size: " + (writer.BaseStream.Length - 4));
                    writer.BaseStream.Position = 0;
                    ((MemoryStream)writer.BaseStream).WriteTo(ssl);
                }                 //using
                LoginMessages resp = LoginMessages.none;
                using (BinaryReader reader = new BinaryReader(CSCommon.getData(client, 5000)))
                {
                    resp       = (LoginMessages)reader.ReadInt32();
                    m_messages = resp;
                    if ((resp & LoginMessages.serverAssignedTag) == LoginMessages.serverAssignedTag)
                    {
                        serverTag = reader.ReadString();
                        System.Diagnostics.Trace.WriteLine("Server sent tag: " + serverTag);
                    }
                }                 //using
                if ((resp & LoginMessages.demo) == LoginMessages.demo)
                {
                    BPCSharedComponent.ExtendedAudio.DSound.playAndWait(BPCSharedComponent.ExtendedAudio.DSound.NSoundPath + "\\cd" + Common.getRandom(1, 2) + ".wav");
                }
                if ((resp & LoginMessages.noCallSign) == LoginMessages.noCallSign)
                {
                    BPCSharedComponent.ExtendedAudio.DSound.playAndWait(BPCSharedComponent.ExtendedAudio.DSound.NSoundPath + "\\ncs.wav");
                }
                if ((resp & LoginMessages.badVersion) == LoginMessages.badVersion)
                {
                    SapiSpeech.speak("There is a newer version of TDV available. Please update before logging on.", SapiSpeech.SpeakFlag.noInterrupt);
                    return(false);
                }
                if ((resp & LoginMessages.wrongCredentials) == LoginMessages.wrongCredentials)
                {
                    BPCSharedComponent.ExtendedAudio.DSound.playAndWait(BPCSharedComponent.ExtendedAudio.DSound.NSoundPath + "\\pw2.wav");
                    return(false);
                }
            }
            catch (IOException)
            {
                error = true;
            }
            catch (TimeoutException)
            {
                error = true;
            }
            if (error)
            {
                return(false);
            }

            if (log)
            {
                theFile = new StreamWriter(Addendums.File.appPath + "\\server_output.log");
            }
            live          = true;
            processThread = new Thread(processRCV);
            processThread.Start();
            return(true);
        }
Пример #20
0
        private static void showDevices()
        {
            InputDeviceCollection dList = null;
            ////holds keyboards
            InputDeviceCollection dList2 = null;

            ////holds game controllers
            dList = DirectInput.GetDevices(DeviceClass.Keyboard, DeviceEnumerationFlags.AttachedOnly);
            ////enumerator for keyboards
            dList2 = DirectInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly);
            ////enumerator for all game controllers

            DeviceInstance[] devList = null;
            devList = (DeviceInstance[])(Array.CreateInstance(typeof(DeviceInstance),
                                                              (dList2 == null) ? 1 : 2));
            foreach (DeviceInstance d in dList)
            {
                devList[0] = d;
                break;
            }
            if (dList2 != null)
            {
                foreach (DeviceInstance d in dList2)
                {
                    devList[1] = d;
                    break;
                }
            }
            string[] devListSTR = new string[(dList2 == null) ? 1 : 2];
            devListSTR[0] = "mainmenu_5_1_1.wav";
            if (dList2 != null)
            {
                devListSTR[1] = "mainmenu_5_1_2.wav";
            }
            int mindex = Common.sVGenerateMenu(null, devListSTR);

            if (mindex == -1)
            {
                return;
            }
            ////exit menu
            if (mindex > 0)
            {
                ////chose joystick
                ////so config it
                dxInput.DInputInit(Common.mainGUI.Handle, devList[mindex].InstanceGuid);
                configureJS(devList[mindex].InstanceGuid);
                KeyMap.readFromFile();
                SecondarySoundBuffer confirm = DSound.LoadSound(DSound.NSoundPath + "\\gce.wav");
                DSound.PlaySound(confirm, true, false);
                while (DSound.isPlaying(confirm))
                {
                    Thread.Sleep(10);
                }
                DSound.unloadSound(confirm);
                confirm = null;
            }
            else
            {
                if (dxInput.JSDevice != null)
                {
                    dxInput.JSDevice.Unacquire();
                    dxInput.JSDevice = null;
                }         //if !null
                KeyMap.readFromFile();
            }             //if chose keyboard
        }