Example #1
0
        public string TestMethod01(NetPlug src, string input)
        {
            if (input != "TestMethod01Input")
                return "FAILED";

            return "TestMethod01Return";
        }
Example #2
0
        public bool AcceptChallenge(NetPlug from, int opponentClientID)
        {
            bool bRet = false;
            lock (mGlobalLock)
            {
                RealtimePlayer self = from.UserData as RealtimePlayer;
                RealtimePlayer opp = null;
                Challenge theChallenge = null;

                foreach (Challenge challenge in self.Challenges)
                {
                    if (challenge.SourcePlayer.ClientID == opponentClientID)
                    {
                        theChallenge = challenge;
                        opp = theChallenge.SourcePlayer;
                        break;
                    }
                }

                if (theChallenge != null)
                {
                    bRet = true;
                    StartMatch(self, opp, theChallenge.MatchLengthSeconds, theChallenge.TurnLengthSeconds);
                }
            }
            return bRet;
        }
Example #3
0
        public string TestMethod03(NetPlug src)
        {
            string ret = "";

            for (int c = 0; c < 666; c++)
                ret += "-";

            return ret;
        }
Example #4
0
        public int Challenge(NetPlug from, int clientID, string msg, int matchLengthSeconds, int turnLengthSeconds)
        {
            lock (mGlobalLock)
            {
                int ret = -1;	// Devolvemos el clientID en caso de exito para ayudar al cliente

                if (!MATCH_DURATION_SECONDS.Contains(matchLengthSeconds))
                    throw new Exception("Nice try");

                if (!TURN_DURATION_SECONDS.Contains(turnLengthSeconds))
                    throw new Exception("Nice try");

                RealtimePlayer self = from.UserData as RealtimePlayer;

                // Es posible que nos llegue un challenge cuando ya nos han aceptado otro de los nuestros
                if (self.Room != null)
                {
                    RealtimePlayer other = null;

                    for (int c = 0; c < self.Room.Players.Count; c++)
                    {
                        if (self.Room.Players[c].ClientID == clientID)
                        {
                            other = self.Room.Players[c];
                            break;
                        }
                    }

                    if (other != null && !HasChallenge(self, other))
                    {
                        Challenge newChallenge = new Challenge();
                        newChallenge.SourcePlayer = self;
                        newChallenge.TargetPlayer = other;
                        newChallenge.Message = msg;
                        newChallenge.MatchLengthSeconds = matchLengthSeconds;
                        newChallenge.TurnLengthSeconds = turnLengthSeconds;

                        self.Challenges.Add(newChallenge);
                        other.Challenges.Add(newChallenge);

                        ret = clientID;

                        other.TheConnection.Invoke("PushedNewChallenge", newChallenge);
                    }
                }

                return ret;
            }
        }
Example #5
0
 public string TestMethod04(NetPlug src)
 {
     return src.ID.ToString();
 }
Example #6
0
 public void TestMethod02(NetPlug src, float input)
 {
     if (input != 666.666f)
         Log.log(REALTIME, "TestMethod02");
 }
Example #7
0
 public abstract void OnClientLeft(NetPlug client);
Example #8
0
 public abstract void OnClientConnected(NetPlug client);
Example #9
0
        private void ProcessAccept(SocketAsyncEventArgs acceptSAEA)
        {
            if (acceptSAEA.SocketError != SocketError.Success)
            {
                // acceptSAEA.SocketError == SocketError.OperationAborted. This will happen for example when we close the listening
                // socket inside the server Stop. We make sure then that accepting socket is cleaned up.
                acceptSAEA.AcceptSocket.Close();
            }
            else
            {
                if (mListeningSocket == null)
                    throw new NetEngineException("WTF");

                // If we are a policy server, message mode will be always string suffixed.
                NetPlug.MessageMode messageMode = mPolicyServerMode ? NetPlug.MessageMode.StringSuffixMode : NetPlug.MessageMode.BinaryPrefixMode;
                NetPlug newNetConnection = null;

                lock (mNetPlugsLock)
                {
                    // For the Policy Server, we add a BIG number to the ID just to make it easier to debug
                    newNetConnection = new NetPlug(this, mCumulativePlugs + (mPolicyServerMode ? 100000000 : 0), acceptSAEA.AcceptSocket, messageMode);

                    mNetPlugs.Add(newNetConnection);

                    if (mNetPlugs.Count > mMaxConcurrentPlugs)
                        mMaxConcurrentPlugs = mNetPlugs.Count;

                    mCumulativePlugs++;

                    Log.log(NetEngineMain.NETENGINE_DEBUG_BUFFER, "NetPlugs: " + mNetPlugs.Count + " Allocated: " + mBufferManager.AllocatedCount );
                }

                newNetConnection.Start();
            }
        }
Example #10
0
        internal void OnConnectionClosed(NetPlug np)
        {
            lock (mNetPlugsLock)
            {
                mNetPlugs.Remove(np);
            }

            // One connection available!
            mMaxConnectionsEnforcer.Release();
        }
Example #11
0
        public bool SwitchLookingForMatch(NetPlug from)
        {
            bool bRet = false;

            lock (mGlobalLock)
            {
                RealtimePlayer self = from.UserData as RealtimePlayer;
                self.LookingForMatch = !self.LookingForMatch;

                bRet = self.LookingForMatch;
            }

            return bRet;
        }
Example #12
0
        public override void OnClientLeft(NetPlug client)
        {
            lock (mGlobalLock)
            {
                RealtimePlayer leavingPlayer = client.UserData as RealtimePlayer;

                // Es posible que no haya RealtimePlayer porque no haya llegado a hacer login, aunque haya conectado
                if (leavingPlayer != null)
                {
                    if (leavingPlayer.Room != null)
                    {
                        LeaveRoom(leavingPlayer);
                    }
                    else
                    {
                        // Como despues de un partido dejamos que sean los propios clientes los que se unan a la habitacion,
                        // es posible tambien que no tenga ni room ni partido, si pilla justo en esa transicion
                        if (leavingPlayer.TheMatch != null)
                            OnPlayerDisconnectedFromMatch(leavingPlayer);
                    }
                }
            }
        }
Example #13
0
        public override void OnClientConnected(NetPlug client)
        {
            Log.log(REALTIME_DEBUG, "************************* OnClientConnected  " + client.ID + " *************************");

            lock (mGlobalLock)
            {
                if (mBroadcastMsg != "")
                    client.Invoke("PushedBroadcastMsg", mBroadcastMsg);
            }
        }
Example #14
0
        public bool LogInToDefaultRoom(NetPlug myConnection, string facebookSession)
        {
            lock (mGlobalLock)
            {
                bool bRet = false;

                // Como se vuelve a llamar aqui despues de jugar un partido, nos aseguramos de que la conexion este limpia para
                // la correcta recreacion del RealtimePlayer
                myConnection.UserData = null;

                using (SoccerDataModelDataContext theContext = new SoccerDataModelDataContext())
                {
                    Session theSession = (from s in theContext.Sessions
                                          where s.FacebookSession == facebookSession
                                          select s).FirstOrDefault();

                    if (theSession == null)
                        throw new Exception("Invalid session sent by client");

                    Player theCurrentPlayer = theSession.Player;

                    // Sólo permitimos una conexión para un player dado.
                    CloseOldConnectionForPlayer(theCurrentPlayer);

                    Team theCurrentTeam = theCurrentPlayer.Team;

                    // Unico punto de creacion del RealtimePlayer
                    RealtimePlayer theRealtimePlayer = new RealtimePlayer();

                    theRealtimePlayer.PlayerID = theCurrentPlayer.PlayerID;
                    theRealtimePlayer.ClientID = myConnection.ID;
                    theRealtimePlayer.FacebookID = theCurrentPlayer.FacebookID;
                    theRealtimePlayer.Name = theCurrentTeam.Name;
                    theRealtimePlayer.PredefinedTeamName = theCurrentTeam.PredefinedTeam.Name;
                    theRealtimePlayer.TrueSkill = theCurrentTeam.TrueSkill;

                    myConnection.UserData = theRealtimePlayer;
                    theRealtimePlayer.TheConnection = myConnection;

                    JoinPlayerToPreferredRoom(theRealtimePlayer);

                    bRet = true;

                    Log.log(REALTIME_DEBUG, theCurrentPlayer.FacebookID + " " + theRealtimePlayer.ClientID +  " logged in: " + theCurrentPlayer.Name + " " + theCurrentPlayer.Surname + ", Team: " + theCurrentTeam.Name);
                }

                return bRet;
            }
        }
Example #15
0
 public string GetBroadcastMsg(NetPlug from)
 {
     lock (mGlobalLock)
     {
         return mBroadcastMsg;
     }
 }