summaryrefslogtreecommitdiff
path: root/src/map/map.cpp
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2015-01-03 21:07:56 -0800
committerBen Longbons <b.r.longbons@gmail.com>2015-01-03 21:58:26 -0800
commit00da6b5977574a0564169172227d8aab45be188f (patch)
treedd52eee506a98e1eb9fcdea52e7db25079a7ad28 /src/map/map.cpp
parent4c91abd6a020ee030114ae3f22d8f6066e7528be (diff)
downloadtmwa-00da6b5977574a0564169172227d8aab45be188f.tar.gz
tmwa-00da6b5977574a0564169172227d8aab45be188f.tar.bz2
tmwa-00da6b5977574a0564169172227d8aab45be188f.tar.xz
tmwa-00da6b5977574a0564169172227d8aab45be188f.zip
Switch MATCH to separate begin/end macros
The for loop trick turned out to be very prone to infinite loops at runtime. It's better to force compiler errors even if it's ugly.
Diffstat (limited to 'src/map/map.cpp')
-rw-r--r--src/map/map.cpp44
1 files changed, 24 insertions, 20 deletions
diff --git a/src/map/map.cpp b/src/map/map.cpp
index 784319f..e2c38a7 100644
--- a/src/map/map.cpp
+++ b/src/map/map.cpp
@@ -1247,36 +1247,40 @@ void map_setcell(Borrowed<map_local> m, int x, int y, MapCell t)
int map_setipport(MapName name, IP4Address ip, int port)
{
Option<P<map_abstract>> md_ = maps_db.get(name);
- if OPTION_IS_SOME_NOLOOP(md, md_)
+ OMATCH_BEGIN (md_)
{
- if (md->gat)
+ OMATCH_CASE_SOME (md)
{
- // local -> check data
- if (ip != clif_getip() || port != clif_getport())
+ if (md->gat)
{
- PRINTF("from char server : %s -> %s:%d\n"_fmt,
- name, ip, port);
- return 1;
+ // local -> check data
+ if (ip != clif_getip() || port != clif_getport())
+ {
+ PRINTF("from char server : %s -> %s:%d\n"_fmt,
+ name, ip, port);
+ return 1;
+ }
+ }
+ else
+ {
+ // update
+ P<map_remote> mdos = md.downcast_to<map_remote>();
+ mdos->ip = ip;
+ mdos->port = port;
}
}
- else
+ OMATCH_CASE_NONE ()
{
- // update
- P<map_remote> mdos = md.downcast_to<map_remote>();
+ // not exist -> add new data
+ auto mdos = make_unique<map_remote>();
+ mdos->name_ = name;
+ mdos->gat = nullptr;
mdos->ip = ip;
mdos->port = port;
+ maps_db.put(mdos->name_, std::move(mdos));
}
}
- else
- {
- // not exist -> add new data
- auto mdos = make_unique<map_remote>();
- mdos->name_ = name;
- mdos->gat = nullptr;
- mdos->ip = ip;
- mdos->port = port;
- maps_db.put(mdos->name_, std::move(mdos));
- }
+ OMATCH_END ();
return 0;
}