public string TestMethod01(NetPlug src, string input) { if (input != "TestMethod01Input") return "FAILED"; return "TestMethod01Return"; }
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; }
public string TestMethod03(NetPlug src) { string ret = ""; for (int c = 0; c < 666; c++) ret += "-"; return ret; }
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; } }
public string TestMethod04(NetPlug src) { return src.ID.ToString(); }
public void TestMethod02(NetPlug src, float input) { if (input != 666.666f) Log.log(REALTIME, "TestMethod02"); }
public abstract void OnClientLeft(NetPlug client);
public abstract void OnClientConnected(NetPlug client);
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(); } }
internal void OnConnectionClosed(NetPlug np) { lock (mNetPlugsLock) { mNetPlugs.Remove(np); } // One connection available! mMaxConnectionsEnforcer.Release(); }
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; }
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); } } } }
public override void OnClientConnected(NetPlug client) { Log.log(REALTIME_DEBUG, "************************* OnClientConnected " + client.ID + " *************************"); lock (mGlobalLock) { if (mBroadcastMsg != "") client.Invoke("PushedBroadcastMsg", mBroadcastMsg); } }
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; } }
public string GetBroadcastMsg(NetPlug from) { lock (mGlobalLock) { return mBroadcastMsg; } }