[Unity 5]matchmaking : matches not visible - unity3d

I need your help please because I have an issue about matchmaking. I try to make a Pong playable online. When i use NetworkHUD, and I use Matchmaker, I can create a match, and the other app (on the same computer for now) detach it and can join it. But, when I don't use it, but I use matchmaker manually, I can create a match, I have a success response, I can find this match in the same app, but, in my second app, I can't find match created by the first app.
Can you help me?
Here are two functions in which I create match :
public void matchmaking()
{
nm.StartMatchMaker();
networkMatch.ListMatches(0, 20, "", OnMatchList);
Debug.LogError ("NBR MATCH " +matchList.Count);
if (matchList.Count == 0)
{
CreateMatchRequest match = new CreateMatchRequest();
match.name = "OrionPongRoom";
match.size = 2;
match.advertise = true;
match.password = "";
networkMatch.CreateMatch(match, OnMatchCreate);
}
else
Debug.Log ("******matches found"+matchList.Count);
}
void OnMatchCreate(CreateMatchResponse matchResponse)
{
if (matchResponse.success)
{
Debug.LogError("Create match succeeded");
matchCreated = true;
MatchInfo matchInfo = new MatchInfo(matchResponse);
Utility.SetAccessTokenForNetwork(matchResponse.networkId, new NetworkAccessToken(matchResponse.accessTokenString));
nm.StartHost(matchInfo);
NetworkServer.Listen(9000);
//NetworkServer.Listen(new MatchInfo(matchResponse), 9000);
}
else
{
Debug.LogError ("Create match failed");
}
}

You need to write
if (matchList.Count == 0)
{
CreateMatchRequest match = new CreateMatchRequest();
match.name = "OrionPongRoom";
match.size = 2;
match.advertise = true;
match.password = "";
networkMatch.CreateMatch(match, OnMatchCreate);
}
else
Debug.Log ("******matches found"+matchList.Count);
in OnMatchList method.
void OnMatchList(ListMatchResponse matchList)
{
if (matchList.Count == 0)
{
CreateMatchRequest match = new CreateMatchRequest();
match.name = "OrionPongRoom";
match.size = 2;
match.advertise = true;
match.password = "";
networkMatch.CreateMatch(match, OnMatchCreate);
}
else
Debug.Log ("******matches found"+matchList.Count);
}
Because of Network Delays etc, matchmaking server can not send response synchronous.

Related

How to read event source name from EventLogRecord?

I am reading event log records as -
EventLogQuery query = new EventLogQuery(_eventLogName, PathType.LogName, sQuery);
query.ReverseDirection = true; // this tells it to start with newest first
List<EventRecord> eventRecords = new List<EventRecord>();
using (EventLogReader reader = new EventLogReader(query))
{
reader.BatchSize = 100;
EventRecord eventRecord;
while ((eventRecord = reader.ReadEvent()) != null)
{
if (_lastModified == null)
{
_lastModified = eventRecord.TimeCreated;
}
eventRecords.Add(eventRecord);
}
}
I am not sure how may i get Event Source value for each event.
Any help please...

How to properly forward/redirect calls with pjsua2

I can't find info on the net how to forward a call with pjsua2.
Currently Im trying with the xfer method but Im getting:
../src/pjsip-ua/sip_inv.c:3942: inv_on_state_null: Assertion `!"Unexpected transaction type"' failed.
There is no information about this error.
This is my code Im trying:
void MyAccount::onIncomingCall(OnIncomingCallParam &iprm)
{
MyCall *call = new MyCall(*this, iprm.callId);
...
calls.push_back(call);
...
QString fwd_to = fwd(QString::fromStdString(ci.remoteUri));
if(fwd_to != "NO_FWD")
{
info+="*** Xfer Call: ";
info+=QString::fromStdString(ci.remoteUri);
info+=" [";
info+=QString::fromStdString(ci.stateText);
info+="]\n";
infoChanged=true;
CallOpParam prm1;
prm1.statusCode = (pjsip_status_code)200;
call->answer(prm1);
pj_thread_sleep(2000);
CallOpParam prm2(true);
call->xfer(fwd_to.toStdString(), prm2);
}
else
{
// standart incoming
...
}
}
fwd is my own function which search a database if it needs to forward the call
I did something like this and works, dont know if some other way exist:
(answering with no media, setting flag and in other thread xfering call to fwd_to string)
if(fwd_to != "NO_FWD")
{
CallOpParam prm1;
prm1.statusCode = (pjsip_status_code)200;
call->answer(prm1);
call->fwd_to = fwd_to;
call->fwd=true;
}
FwdThread *fwd_thread = new FwdThread();
fwd_thread->start();
void FwdThread::run()
{
static pj_thread_desc s_desc;
static pj_thread_t *s_thread;
pj_thread_register("FwdThread", s_desc, &s_thread);
loop();
}
void FwdThread::loop()
{
while(1)
{
for(auto &call : pjt->v_calls)
{
if(call->fwd && call->answered)
{
call->fwd=false;
CallOpParam prm2(true);
call->xfer(call->fwd_to.toStdString(), prm2);
}
}
if(pjt->Stop)
break;
pj_thread_sleep(500);
}
}

Entity framework tracking wrong model object after helper method

Below is some basic code that's a part of our Create controller method. If a certain checkbox is selected, we want to create a copy of the agenttransmission object we are currently creating, with a couple fields altered.
When the program goes into the helper method, it creates the sub record without incident, however for some reason, when the program finishes and comes back to the Create method, the model object agenttransmission becomes the sub model object. All value, including the PK are suddenly pressent in the agenttransmission object.
Not sure how this is happening since there is a string return value on the helper method and no fields are touched on the agenttransmission record.
Create method
//Create substat if requested
if (agenttransmission.OverrideId)
{
status += ". " + CreateSubStat(agenttransmission);
}
Helper method
public string CreateSubStat(AgentTransmission master)
{
string msg = string.Empty;
if (ModelState.IsValid)
{
using (AgentResourcesEntities tempDb = new AgentResourcesEntities())
{
try
{
//Check to see if substat already exists
var check = (from a in db.AgentTransmission
where a.ParentId == master.ID && a.RecordStatus.Equals("P")
select a).ToList();
if (check.Count > 0) return string.Empty;
//If not add dependent record
AgentTransmission sub = master;
sub.OverrideId = false;
sub.DRMCompanyId = string.Empty;
sub.CONCode = "00";
sub.RecordStatus = "P";
sub.ParentId = master.ID;
sub.ID = 0;
sub.IsSubstat = true;
sub.SendToDynamicsOptions = "N";
sub.SendToNMF = false;
//Remove blanks from ClearinghousePartners list
sub.ClearinghousePartners.RemoveAll(
x =>
string.IsNullOrWhiteSpace(x.ClearingHouseName) &&
string.IsNullOrWhiteSpace(x.TradingPartnerName) && x.StartDate == null);
sub.AgentRelationshipCodes.RemoveAll(
x =>
string.IsNullOrWhiteSpace(x.RelationshipId) &&
!x.EffectiveDate.HasValue && x.Id == 0);
foreach (var item in sub.AgentRelationshipCodes)
{
item.LastChangeDate = DateTime.Now;
item.LastChangeId = SecurityRules.GetUserName(User);
item.AgentTransmission = sub;
item.AgtTableId = sub.ID;
}
foreach (var item in sub.ClearinghousePartners)
{
item.AgentTransmission = sub;
item.AgtTransId = sub.ID;
}
db.AgentTransmission.Add(sub);
db.SaveChanges();
msg = "Substat saved with status of 'Dependent'.";
}
catch (DbEntityValidationException dbEx)
{
msg = "Error creating substat. IT has been informed and will respond shortly.";
SendEmail.ErrorMail(dbEx.Message, SecurityRules.GetUserName(User));
}
catch (Exception ex)
{
msg = "Error creating substat. IT has been informed and will respond shortly.";
SendEmail.ErrorMail(ex, SecurityRules.GetUserName(User));
}
}
}
else
{
//Invalid ModelState error handling
string messages = string.Join("; ", ModelState.Values
.SelectMany(x => x.Errors)
.Select(x => x.ErrorMessage));
SendEmail.ErrorMail("Error Creating Substat: " + messages, SecurityRules.GetUserName(User));
msg = "Error creating substat. IT has been informed and will respond shortly.";
}
return msg;
}
The line...
AgentTransmission sub = master;
...doesn't copy master to sub, but assigns it to sub, because AgentTransmission is a reference type. So everything you do to sub you do to master.
You either must clone master to sub (create a new object and copy its properties), or re-fetch the master object from the database after the CreateSubStat call.

WP - How to constantly update my location

Currently my location not updating when I change it to different location via emulator. But it will change after I restart my application. This is what I write when the app launch
private void Application_Launching(object sender, LaunchingEventArgs e)
{
IsolatedStorageSettings Settings = IsolatedStorageSettings.ApplicationSettings;
GeoCoordinate DefaultLocation = new GeoCoordinate(-6.595139, 106.793801);
Library.GPSServices MyGPS;
if (!Settings.Contains("FirstLaunch") || (bool)Settings["FirstLaunch"] == true)
{
Settings["FirstLaunch"] = false;
Settings["LastLocation"] = DefaultLocation;
Settings["SearchRadius"] = 1;
}
//If key not exist OR key value was set to false, ask for permission to use location
if (!Settings.Contains("LocationService") || (bool)Settings["LocationService"] == false)
{
var result = MessageBox.Show(
"Jendela Bogor need to know your location to work correctly, do you want to allow it?",
"Allow access to your location?",
MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
Settings["LocationService"] = true;
MyGPS = new Library.GPSServices();
}
else
{
Settings["LocationService"] = false;
}
Settings.Save();
}
else if ((bool)Settings["LocationService"] == true)
{
MyGPS = new Library.GPSServices();
}
}
I store my location in my application setting IsolatedStorage with name Settings["LastLocation"]
How should I do to constantly update my location in the Background using MVVM Pattern (MVVM-Light) so my PushPin on map in the ThirdPageView always updated?
EDIT
public GPSServices()
{
if ((bool)Settings["LocationService"] == true)
{
if (_watcher == null)
{
_watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
_watcher.MovementThreshold = 20;
}
StartWatcher();
_watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
_watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);
}
else if ((bool)Settings["LocationService"] == false)
{
StopWatcher();
}
}
private void StartWatcher()
{
_watcher.Start();
}
private void StopWatcher()
{
if (_watcher != null)
_watcher.Stop();
}
private void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
if (e.Position.Location.IsUnknown)
{
MessageBox.Show("Please wait while your position is determined....");
return;
}
Settings["LastLocation"] = e.Position.Location;
Settings.Save();
}
System.Device.Location.GeoCoordinateWatcher provides what you need.
var geoWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
// This event fires every time the device location changes
geoWatcher.PositionChanged += (s, e) => {
//e.Position.Location will contain the current GeoCoordinate
};
geoWatcher.TryStart(false, TimeSpan.FromMilliseconds(2000));
is this helpful for you ? using GeocoordinateWatcher.PositionChanged event?
public Location()
{
GeoCoordinateWatcher location == new GeoCoordinateWatcher();
location.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(location_PositionChanged);
location.Start();
}
//event to track the location change
public void location_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
}

Submitting a WebRequest from within a CLR Trigger

I just implemented a prototype solution for updating my caching server in real-time by assigning a CLR Trigger to a table so that whenever a certain column is updated the URL called from the trigger will update the caching server with the correct data.
It's working fine and the code is as follows:
[Microsoft.SqlServer.Server.SqlTrigger(Name = "AdStatusChanged", Target = "Ads", Event = "FOR UPDATE")]
public static void AdStatusChanged()
{
SqlTriggerContext triggContext = SqlContext.TriggerContext;
int adID = 0, adStatusID_Old = 0, adStatusID_New = 0;
if (triggContext.TriggerAction == TriggerAction.Update)
{
using (SqlConnection conn = new SqlConnection("context connection=true"))
{
conn.Open();
SqlCommand sqlComm = new SqlCommand();
SqlPipe sqlP = SqlContext.Pipe;
sqlComm.Connection = conn;
sqlComm.CommandText = "SELECT AdID, AdStatusID from INSERTED";
SqlDataReader reader = sqlComm.ExecuteReader();
if (reader.Read())
{
adID = reader.GetInt32(0);
adStatusID_New = reader.GetInt32(1);
}
reader.Close();
sqlComm.CommandText = "SELECT AdID, AdStatusID from DELETED WHERE AdID = " + adID;
reader = sqlComm.ExecuteReader();
if (reader.Read())
{
adID = reader.GetInt32(0);
adStatusID_Old = reader.GetInt32(1);
}
}
if (adID == 0 || adStatusID_New == adStatusID_Old)
{
// Check could be more thorough !
return;
}
WebResponse httpResponse = null;
try
{
string apiURL = string.Format("{0}/{1}", "http://localhost:14003/Home", "UpdateAdStatus?adID=" + adID + "&adStatusID=" + adStatusID_New);
var httpWebRequest = (HttpWebRequest)WebRequest.Create(apiURL);
httpWebRequest.Method = "GET";
httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
// check for successful response
}
catch (Exception ex)
{
Log("WebRequest from within SQL Server failed ! " + ex.Message);
}
finally
{
if (httpResponse != null)
{
httpResponse.Close();
}
}
}
}
I would like to have some expert/experienced views on the "CONS" of this approach regarding performance, deadlocks, sql crashing, or other areas that could be of potential concern.
Has anyone tried this (I'm sure many must have) and what was the result ? a successful implementation or did you revert to some other method or updating the cache real-time?